Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multiple analog inputs

Status
Not open for further replies.

poxkix

Member level 5
Joined
Aug 20, 2011
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,948
Specs:
16F877a @ 8Mhz crystal oscillator
MikroC compiler

Problem:
As usual before posting I searched the forum but none I can relate of.
The problem is, the lcd output is just jitter random values. Though, is my configuration correct?

Code:
Code:
// 0x02 = 0010
// 0x04 = 0100
// 0x08 = 1000
// 0x10 = 00010000

unsigned int i;
unsigned int s1, s2, s3, s4, s5;
char strS1[5], strS2[5], strS3[5], strS4[5], strS5[5];

void setUp() {
     PORTB = 0;
     TRISB = 0x01;
     //ADCON1 = 0b0010;
     TRISA  = 0xFF;
     ADCON1 = 0x80;
     TRISC = 0x00;
     
     i = 0;
}

void LCDconf() {
     Lcd_Init(&PORTC);
     Lcd_Cmd(Lcd_CLEAR);
     Lcd_Cmd(Lcd_CURSOR_OFF);
}

void ADConf() {
              s1 = Adc_Read(0);
              s2 = Adc_Read(1);
              s3 = Adc_Read(2);
              s4 = Adc_Read(3);
              s5 = Adc_Read(4);

              IntToStr(s1, strS1);
              Lcd_Out(1,1,strS1);
              IntToStr(s2, strS2);
              Lcd_Out(1,5,strS2);
              IntToStr(s3, strS3);
              Lcd_Out(2,1,strS3);
              IntToStr(s4, strS4);
              Lcd_Out(2,5,strS4);
              IntToStr(s5, strS5);
              Lcd_Out(1,1,strS5);
     }

void main () {
     setUp();
     LCDconf();
     //ADConf();
     
     while(1) {
              ADConf();
              
              if(PORTB.f0==1) {
                if(i==0) {
                  PORTB=0x04;
                  delay_ms(1000);
                  i=1;
                } else if(i==1) {
                    PORTB=0x08;
                    delay_ms(1000);
                    i=2;
                    } else if(i==2) {
                        PORTB=0x10;
                        delay_ms(1000);
                        i=3;
                        } else if(i==3) {
                            PORTB=0x02;
                            delay_ms(1000);
                            i=0;
                            }
              }
     }
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top