yohanevindra
New Member
Im trying to make a simple program light the LEDSs based on the AD conversion value, which will be the position of the variable resistor which is connected to Port A0 on the PICDEM2PLUS board.
This is my code
When I insert breakpoints and run it, the ADRESH/ADRESL registers are always 0. What am I doing wrong here?
This is my code
Code:
#include <p18f4520.h>
#define LED1 0x01
#define LED2 0x02
#define LED3 0x03
#define LED4 0x04
char table[4];
//#pragma config
#pragma interrupt adisr
void adisr ()
{
if (PIR1bits.ADIF = 1)
{
PORTB = table[ADRESH];
PIR1bits.ADIF = 0;
}
}
#pragma code ad_high_pri = 0x0008
void high_prio_int()
{
_asm
GOTO adisr
_endasm
}
#pragma code
void init_config(void)
{
TRISA = 0x01; //Make A0 an input
TRISB = 0x00;
ADCON1 = 0x00;
ADCON2 = 0x00;
ADCON0 = 0x01; //Select A/D Channel 0 PortA0 and enable A/D module
IPR1 = 0x00; //Reset ADIF flag
PIR1 = 0x00;
RCON = 0x80;
PIE1 = 0x40;
INTCON = 0xA0; //Enabble global interrupts
T0CON = 0b11000000;
ADRESH = 0x00;
ADRESL = 0x00;
}
void main(void)
{
table[0] = LED1;
table[1] = LED2;
table[2] = LED3;
table[3] = LED4;
init_config();
while (INTCONbits.TMR0IF = 0)
{
}
while(1);
}
When I insert breakpoints and run it, the ADRESH/ADRESL registers are always 0. What am I doing wrong here?