Program to Multiply two 8bit numbers using PIC18F MCU in MPLAB IDE using Embedded C

Program:

#include <xc.h>

void main(void) {
    
    TMR0H = 0x1B;  // 1B = 27
    TMR0L = 0x0A;  // 0A = 10
    
    int a = TMR0H * TMR0L; // 27 * 10 = 270
     
    TRISB = 0;
    TRISC = 0;
    
    PORTB = a / 256;  // 270 in Hex 10E
    PORTC = a % 256;
    
    return;
}

Output:

Fig: Variable Address

Fig: File Register

Fig: Output SFR

Previous
Next Post »