- CODE: SELECT_ALL_CODE
//port definition
//input
#define SW1 PORTB.F0
#define SW2 PORTB.F1
//output
//LED
#define LED1 PORTB.F6
#define LED2 PORTB.F7
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D0_Direction at TRISD0_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
char value[7];
char value2[7];
void introduction(void);
void initialization(void);
void stat_mode(void);
void main()
{
initialization();
introduction();
while(1)
{
unsigned char i;
unsigned portvalue;
unsigned portvalue2;
portvalue=Adc_Read(0);
portvalue2=Adc_Read(1);
portvalue= portvalue/2;
portvalue2=(portvalue2/2);
WordToStr(portvalue, value);
WordToStr(portvalue2,value2);
Lcd_Out(1,1,"TEMP. CEL:");
Lcd_Out(1,12,value);
Lcd_Out(1,16,"C");
Lcd_Out(2,1,"HUMI. RH :");
Lcd_Out(2,12,value2);
Lcd_Out(2,16,"%");
delay_ms(1000);
for(i=0;i<13;i++)
{
Uart1_Write(value[i]);
//Usart_Write('\n');
//Usart_Write(value2[i]);
}
Uart1_Write('\n');
for(i=0;i<13;i++)
{
//Usart_Write(value[i]);
//Usart_Write('\n');
Uart1_Write(value2[i]);
}
} }
void initialization(void)
{
PORTA = 0; // Clear Port
PORTB = 0;
TRISA=0b11111111;
TRISB=0b00000000;
TRISD=0;
ADCON1=0;
ADC_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
delay_ms(150);
Uart1_Init(9600);
}
void introduction()
{
unsigned char i;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"WELCOME");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," WIRELESS ");
Lcd_Out(2,1," DATALOGGER ");
delay_ms(2000);
for(i=0; i<16; i++) { // Move text to the left 16 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
delay_ms(80);
}
Lcd_Cmd(_LCD_CLEAR);
}
At first in the beginning , the LCD will be showing black boxes and once reset button is pressed on the SK40C , the LCD will function as according to the coding but at the temperature and humidity reading showing some readings of random number as the sensor is not even connected to the RA0 and RA1. Im using LM35 , Cytron Humidity Sensor , SK40C and PIC16F877A. Need help in this.