mohdismiaswaly WROTE:Hi,
I a newbie here..how to post thread here?
Cannot find any button to click...
TQ
It seem you seldom join forum discussion. You should see "New Topic" on the left corner, example under this category, "PIC Microcontroller".
mohdismiaswaly WROTE:Hi,
I a newbie here..how to post thread here?
Cannot find any button to click...
TQ
choohao WROTE:Sorry for the above coding... i means my LCD show a long square bar. may i have a workable coding? i not sure is the my coding or LCD problem~~
If LCD then, i will take back to cytron have a ask..
#include<p18f4520.h>
//===============define IO port=============================
#define lcd PORTC
#define RS RA2
#define E RA5
#define [color=#FF0000]CHANNEL0 0b00000001[/color] // AN0
#define [color=#FF0000]CHANNEL1 0b00000101[/color] // AN1
#define buzzer RD0
#define ledA RD1
#define ledB RD2
//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
unsigned short read_temp(void);
//====================MAIN================================
unsigned short result;
unsigned short temp,tempA,tempB;
void main(void)
{
ADRESH=0; //clear A/D result
ADRESL=0; //clear A/D result
//setting ADCON1 Register
[b][color=#FF0000]ADCON1=0b00011101;[/color][/b] // A/D result right justified,
// configure RA2 and RA5 as digital I/O
[color=#FF0000]ADCON2=0b10001010;[/color]
TRISA=0b11011011; //configure PORTA I/O direction
TRISD=0b00000000; //configure PORTD as output
TRISC=0b00000000; //configure PORTC as output
PORTA=0;
PORTB=0;
while(1)
{
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set
lcd_goto(0); //cursor start from beginning
//display character on LCD
send_char(' ');
send_char('T');
send_char('E');
send_char('M');
send_char('P');
send_char('.');
send_char('A');
send_char('=');
lcd_goto(20); //cursor go to 2nd line of the LCD
//display character on LCD
send_char(' ');
send_char('T');
send_char('E');
send_char('M');
send_char('P');
send_char('.');
send_char('B');
send_char('=');
while(1) //infinity loop
{
//sensor A
ADCON0=CHANNEL0; //CHANNEL1=0b00000101
lcd_goto(8);
read_adc();
temp=read_temp();
dis_num(temp/10);
send_char('.');
dis_num(temp%10);
send_char(0b11011111);
send_char('C');
send_char(' ');
send_char(' ');
tempA=temp;
//sensor B
ADCON0=CHANNEL1; //CHANNEL0=0b00000001
lcd_goto(28);
read_adc();
temp=read_temp();
dis_num(temp/10);
send_char('.');
dis_num(temp%10);
send_char(0b11011111);
send_char('C');
send_char(' ');
send_char(' ');
tempB=temp;
if((tempA>=250)&&(tempB<400)) // *****************************************
{ // * LED A and Fan A activated only for *
PORTDbits.RD0=1;//ledA=1; // * temperature A greater than 40'C *
PORTDbits.RD1=0;//ledB=0; // * and temperature B less than 35'C *
PORTDbits.RD2=0;//buzzer=0;
}
else if((tempB>50)&&(tempA<=150)) // *****************************************
{ // * LED B and Fan B activated only for *
PORTDbits.RD0=0;//ledA=0; // * temperature A less than 40'C and *
PORTDbits.RD1=1;//ledB=1; // * temperature B greater than 35'C *
PORTDbits.RD2=0;//buzzer=0;
}
delay(2000);
}
}
}
Users browsing this forum: No registered users and 13 guests