Post
by Ian »
Startup code needs to be in the startup not the main loop.
Also move the Anagloue>Digital IO to the start.
e.g. -
#include <system.h>
main()
{
adcon1=0x07; // Do Analogue port to digital IO first thing
set_bit(STATUS, RP0); //SELECTS BANK 1
TRISA=0x00; //MAKES PORTA outPUT
TRISB=0xff; //MAKES PORTB inPUT
clear_bit(STATUS, RP0); //SELECTS BANK 0
int count=0;
while(1)
{
if(input_pin_port_b(7))
{
count=count+1;
}
else if(input_pin_port_b(6))
{
count=count-1;
}
if(count==1)
{
output_high_port_a(0);
} else {
output_low_port_a(0);
}
if(count==2)
{
output_high_port_a(1);
} else {
output_low_port_a(1);
}
if(count==3)
{
output_high_port_a(2);
} else {
output_low_port_a(2);
}
// added a delay to see it working in XT
delay_s(1);
}
}
Also here is the corrected code for the other program you posted about.
#include <system.h>
main()
{
adcon1=0x07; // Do Analogue port to digital IO first thing
set_bit(STATUS, RP0); //SELECTS BANK 1
TRISB=0x00; //MAKES PORTB OUTPUT
TRISA=0xff; //MAKES PORTA INPUT
clear_bit(STATUS, RP0); //SELECTS BANK 0
if(input_pin_port_a(0))
{
PORTB=0xff;
} else {
PORTB=0x00;
}
}