by mohdismiaswaly » Thu Sep 12, 2013 11:53 pm
Hello everyone,
Below is the picture of my circuit connection. Humidity sensor is connected to pin RA0 (analog input) and all pin PORTD connected to 7 segment display (common anode) as output. What I want to do is to display ONLY the content of ADRESL registers to 7 segment display.
Note:
white wire=output from sensor connected to pin RA0
yellow wire=ground from sensor connected to ground to PIC
blue wire=output from PIC of PORTD pins (RD0-RD7)
red wire=Vdd (5V) from PIC to 7segment display
The problem is I write this code:
#include <htc.h>
main(void)
{
TRISC=0 ;
TRISD=0 ;
TRISAbits.TRISA0=0;
ADCON0 = 0x81 ;
ADCON1 = 0xcE ;
PORTA=0;
PORTC=0;
PORTD=0;
while(1)
{
delay_ms(1) ;
ADCON0bits.GO = 1 ;
while(ADCON0bits.DONE == 1) ;
PORTD=ADRESL;
PORTC=ADRESH;
delay_ms(3000);
}
}
delay_ms(unsigned int x)
{
for(;x>0;x--);
{
T0CON=0x80; //Fosc 4MHz, Timer 0,16-bit mode, prescaler 1:2, use internal clock, increment on positive-edge
TMR0H=0x9E;
TMR0L=0X57;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;
}
}
Anything goes wrong? I am not sure the setting for ADCON0 and ADCON1. I am also not sure about the code I highlight in red colour above. Are they all correct?
- Attachments
-
- circuit connection