killivolt
Well-Known Member
Working out of a book; I am at a point the code provided does not seem to work right.
I'm a noob; I'm also using MPLAB's simulator. I run this code; but it skips my "switch" case statements?
What do you think is out of order.
This is EDITED: It should be this z = z & 0x3; Not this z = z &0x30; //mask the unused bits
(I was confused about HEX value in the above statement and wrote the wrong thing for Z =)
I'm a noob; I'm also using MPLAB's simulator. I run this code; but it skips my "switch" case statements?
What do you think is out of order.
Code:
Write A PIC 18 program to read RB0 and RB1 bits issue ASCII character to PD according to the following table:
RB1 RB0
0 0 send '0' to PORTD ( notice ASCII '0' is 0x30) "I got mixed up here."
0 1 send '1' t0 PORTD
1 0 send '2' to PORTD
1 1 send '3' to PORTD
#include <p18f458.h>
void main(void)
{
unsigned char z;
TRISB = 0xFF; //make Port B an input
TRISD = 0; //make Port D an output
{
z = PORTB; //read Port B
z = z & 0x30; //mask the unused bits
switch (z)
{
case (0): // issue ASCII 0
{
PORTD = '0';
break;
}
case (1): //issue ASCII 1
{
PORTD = '1';
break;
}
case (2): //issue ASCII 2
{
PORTD = '2';
break;
}
case (3): //issue ASCII 3
{
PORTD = '3';
break;
}
}
}
}
This is EDITED: It should be this z = z & 0x3; Not this z = z &0x30; //mask the unused bits
(I was confused about HEX value in the above statement and wrote the wrong thing for Z =)
Last edited: