Yamber
Newbie level 5
- Joined
- May 6, 2013
- Messages
- 8
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,330
Hello Guys,
I'm using LCD 20 x 4 LCD, PIC18f2620 as ou can see on the picture. Here is my code. Please assist to find out why the LEDs are not coming on.
Thanks.
I'm using LCD 20 x 4 LCD, PIC18f2620 as ou can see on the picture. Here is my code. Please assist to find out why the LEDs are not coming on.
Thanks.
Code:
#include "Xa.h"
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#define LED_RED LATCbits.LATC0
#define LED_GREEN LATCbits.LATC1
void init_IO(void);
void init_XLCD(void);
void DelayXLCD(void);
void DelayPORXLCD(void);
void DelayFor18TCY(void);
void init_ADC (void);
unsigned int ADCResult [2];
float voltage;
unsigned char ResultStr [10];
int main(void) {
// long status;
unsigned char i;
init_ADC ();
init_XLCD ();
//************************************
putrsXLCD(" SYSTEM READY");
__delay_ms(80);
WriteCmdXLCD (0x01);
//********************************
while (1){
for ( i = 0; i < 2; i++){
ADCON0bits.CHS = i;
DelayFor18TCY();
ConvertADC ();
while (BusyXLCD ());
ADCResult [i] = (unsigned int) ReadADC ();}
//***********************************
for ( i = 0;i < 2; i++){
voltage = (ADCResult [1]* 5.0/1024);
sprintf (ResultStr, "AD%1u = %4u ",i , ADCResult [i]);
if (i ==1)
SetDDRamAddr (0x40);
putrsXLCD (ResultStr);
SetDDRamAddr (0x13);
sprintf (ResultStr," Voltage = %f ", voltage);
putrsXLCD (ResultStr);
// putrsXLCD ( );
SetDDRamAddr (0x54);
putrsXLCD("THIS IS NOT GOOD");
// putrsXLCD (ResultStr);
}
WriteCmdXLCD (0x02);//Home Screen
if (voltage > 0)
LED_RED = 1;
LED_GREEN = 0;
__delay_ms(60);
LED_GREEN = 1;
__delay_ms(60);
}
}
void init_XLCD(void) {
OpenXLCD(FOUR_BIT & LINES_5X7);
while (BusyXLCD());
WriteCmdXLCD(0x06);//move cursor don't shift display
WriteCmdXLCD(0x0C);// Turn display without cursor
WriteCmdXLCD(0x01);//Clear Screen
}
void init_ADC (void){
OpenADC (ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_2_TAD,
ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS,
ADC_2ANA);
}
void DelayXLCD(void){
Delay1KTCYx(20);
// __delay_ms(20);
}
void DelayPORXLCD(void){
Delay1KTCYx (60);
}
void DelayFor18TCY(void){
Delay10TCYx (20);
return;
}
void init_IO (void){
OSCCON = 0x76;
PORTC =0x00;
// PORTC = 0xFF;
TRISC = 0;
}