Code: Select all
#include <system.h>
void setup_hardware(void)
{
trisb = 0xF0;
trisa = 0xE0;
porta = 0x00;
}
void main(void)
{
setup_hardware();
while (1)
{
portb = 0x01;
if ((portb & 0x10) > 0)
{
porta = 0x01;
}
else if ((portb & 0x20) > 0)
{
porta = 0x04;
}
else if ((portb & 0x40) > 0)
{
porta = 0x03;
}
else if ((portb & 0x80) > 0)
{
porta = 0x05; // '*' is pressed
}
portb = 0x02;
if ((portb & 0x10) > 0)
{
porta = 0x02;
}
else if ((portb & 0x20) > 0)
{
porta = 0x05;
}
else if ((portb & 0x40) > 0)
{
porta = 0x08;
}
else if ((portb & 0x80) > 0)
{
porta = 0x00;
}
portb = 0x04;
if ((portb & 0x10) > 0)
{
porta = 0x03;
}
else if ((portb & 0x20) > 0)
{
porta = 0x06;
}
else if ((portb & 0x40) > 0)
{
porta = 0x09;
}
else if ((portb & 0x80) > 0)
{
porta = 0x0B; // '+' is pressed
}
}
}