bau
Newbie level 3
I am a newbie on Microcontroller. I have written a ADC program which convert the analog signal and display on the led at PORTB and PORTC. I have try simulate with the Proteus, it work well, but, when i download the program into my PIC18F4520, it doesnt work as desired. Below is my program,
#include <p18f4520.h>
#include <delays.h>
#include <portb.h>
#include <adc.h>
#pragma config OSC = HS
#pragma config PWRT = ON
#pragma config WDT = OFF
int temp;
int Hi;
void PortB_isr (void);
#pragma code high_vector=0x08
void high_interrupt (void)
{
_asm GOTO PortB_isr _endasm
}
#pragma interrupt PortB_isr
void PortB_isr (void)
{
INTCONbits.INT0IF=0;
OpenADC(ADC_FOSC_16 & ADC_RIGHT_JUST & ADC_4_TAD, ADC_CH0 & ADC_INT_OFF
& ADC_VREFPLUS_EXT & ADC_VREFMINUS_EXT,5);
SetChanADC(ADC_CH0);
Delay10TCYx( 100 );
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for ADC conversion
temp = ReadADC(); // Read result and put in temp
CloseADC(); // Disable A/D converter
PORTC=temp;
Hi=temp;
Hi>>=8;
PORTD=Hi;
}
void main (void)
{ TRISA=0x0F;
TRISB=0xFF;
TRISC=0x00;
TRISD=0x00;
PORTC=0;
PORTD=0;
ADCON1=0x09;
T0CONbits.T0CS=0;
CMCON=0x07;
CVRCON=0;
OpenRB0INT ( PORTB_CHANGE_INT_ON &
FALLING_EDGE_INT &
PORTB_PULLUPS_OFF);
INTCONbits.GIE = 1;
while(1){}
}
The cystral that i used is 20MHz.
The output of my LED (connected to the PORTC and PORTD) is 0b1100000000 when the AN0 is connected to ground.
I glad to listen from others.......
#include <p18f4520.h>
#include <delays.h>
#include <portb.h>
#include <adc.h>
#pragma config OSC = HS
#pragma config PWRT = ON
#pragma config WDT = OFF
int temp;
int Hi;
void PortB_isr (void);
#pragma code high_vector=0x08
void high_interrupt (void)
{
_asm GOTO PortB_isr _endasm
}
#pragma interrupt PortB_isr
void PortB_isr (void)
{
INTCONbits.INT0IF=0;
OpenADC(ADC_FOSC_16 & ADC_RIGHT_JUST & ADC_4_TAD, ADC_CH0 & ADC_INT_OFF
& ADC_VREFPLUS_EXT & ADC_VREFMINUS_EXT,5);
SetChanADC(ADC_CH0);
Delay10TCYx( 100 );
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for ADC conversion
temp = ReadADC(); // Read result and put in temp
CloseADC(); // Disable A/D converter
PORTC=temp;
Hi=temp;
Hi>>=8;
PORTD=Hi;
}
void main (void)
{ TRISA=0x0F;
TRISB=0xFF;
TRISC=0x00;
TRISD=0x00;
PORTC=0;
PORTD=0;
ADCON1=0x09;
T0CONbits.T0CS=0;
CMCON=0x07;
CVRCON=0;
OpenRB0INT ( PORTB_CHANGE_INT_ON &
FALLING_EDGE_INT &
PORTB_PULLUPS_OFF);
INTCONbits.GIE = 1;
while(1){}
}
The cystral that i used is 20MHz.
The output of my LED (connected to the PORTC and PORTD) is 0b1100000000 when the AN0 is connected to ground.
I glad to listen from others.......