Muhammad Akmal Wong
Newbie level 5
- Joined
- Feb 4, 2014
- Messages
- 8
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 62
I need help for lcd coding to show word such as 'Welcome' I hope someone can help me to solve the problem.
Detail about my coding is i'm going to do a project dat tittle is parking guide system
i'm using switch when the switch is press the red led will light on that's means the parking if filled. and the lcd will show +1 example i have 5 parking slot when the parking is filled the lcd will show +1 until 5 the lcd will show the parking slot in the place is Full lcd show 'Parking Is Full'.
the switch coding i already solve it but i just dont know where or how to put the lcd coding to make it work i'm already read the lcd datasheet ,example ,and so on but i still can't understand anything because i'm still begineer
here are my coding hope u guys can help me
and i'm little blur about the delay routine anyone can suggest what delay routines i should use? 1ms? 100ms? 1us? 100us? thanks for those who are willing to help me i'm still begineer in this pic world.
Detail about my coding is i'm going to do a project dat tittle is parking guide system
i'm using switch when the switch is press the red led will light on that's means the parking if filled. and the lcd will show +1 example i have 5 parking slot when the parking is filled the lcd will show +1 until 5 the lcd will show the parking slot in the place is Full lcd show 'Parking Is Full'.
the switch coding i already solve it but i just dont know where or how to put the lcd coding to make it work i'm already read the lcd datasheet ,example ,and so on but i still can't understand anything because i'm still begineer
here are my coding hope u guys can help me
and i'm little blur about the delay routine anyone can suggest what delay routines i should use? 1ms? 100ms? 1us? 100us? thanks for those who are willing to help me i'm still begineer in this pic world.
Code:
//=============================================================================
// Filename: CodingOnGoing.c
//=============================================================================
#include <htc.h> // Using Hi-Tech C v9.63 compiler, for different
#include <p18f4580.h>
//=============================================================================
// Configuration Bits
//=============================================================================
#pragma config OSC = HS // HS oscillator ?20MHz
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF // Oscillator Switchover mode disabled
#pragma config PWRT = OFF // PWRT disabled
#pragma config WDT = OFF // WDT disabled (control is placed on the SWDTEN bit)
#pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O
#pragma config LVP = OFF // Single-Supply ICSP disabled
#pragma config XINST = OFF // Extended
//=============================================================================
// Define Pins
//=============================================================================
#define ledg1 PORTCbits.RC0 //active High
#define ledg2 PORTCbits.RC1
#define ledg3 PORTCbits.RC2
#define ledg4 PORTCbits.RC3
#define ledg5 PORTCbits.RC4
#define ledg6 PORTCbits.RC5 //for GREEN LED AND YELLOW LED
#define ledr1 PORTAbits.RA0 //active High
#define ledr2 PORTAbits.RA1
#define ledr3 PORTAbits.RA2
#define ledr4 PORTAbits.RA3
#define ledr5 PORTAbits.RA5
#define ledr6 PORTEbits.RE0 //for RED LED
#define sw1 PORTBbits.RB0
#define sw2 PORTBbits.RB1
#define sw3 PORTBbits.RB2
#define sw4 PORTBbits.RB3
#define sw5 PORTBbits.RB6
#define sw6 PORTBbits.RB7 //for switch
#define RS PORTDbits.RD6
#define E PORTDbits.RD7
//=============================================================================
// Main Program
//=============================================================================
//void sendCmd(unsigned char Cmd);//write command to lcd
void sendData(unsigned char Ch, unsigned char rs);//write text to lcd
void initializeLCD(void);
void main(void);
void lcddata(char);
void sendData(unsigned char Ch,unsigned char rs)
{
LATC = Ch; //send 8-bit data
RS = rs; //control RS
E = 1; //pulse E
Delay10TCYx (5); //wait 50 us
E = 0;
Delay10TCYx (5); //wait 50 us
return;
}
void DelayFor18TCY(void)
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD (void)
{
Delay1KTCYx(40);
return;
}
void DelayXLCD(void)
{
Delay1KTCYx(10);
return;
}
void main (void)
{
TRISA = 0;
TRISB = 1;
TRISC = 0;
TRISD = 0;
TRISE = 0;
PORTA = 0;
PORTB = 1;
PORTC = 0;
PORTD = 0;
PORTE = 0;
ADCON1=0b00001111; //<<<declare input and output pin here
initializeLCD();
sendData('W',1);
sendData('e',1);
sendData('l',1);
sendData('c',1);
sendData('o',1);
sendData('m',1);
sendData('e',1);
sendData(' ',1);
sendData('T',1);
sendData('o',1);
sendData(' ',1);
sendData('P',1);
sendData('a',1);
sendData('r',1);
sendData('k',1);
sendData('i',1);
sendData('n',1);
sendData('g',1);
sendData(' ',1);
sendData('G',1);
sendData('u',1);
sendData('i',1);
sendData('d',1);
sendData('e',1);
sendData(' ',1);
sendData('S',1);
sendData('y',1);
sendData('s',1);
sendData('t',1);
sendData('e',1);
sendData('m',1);
sendData('!',1);
sendData('!',1);
sendData('!',1);
OpenXLCD(EIGHT_BIT & LINES_5X7);
putrsXLCD( "Welcome To Parking Guide System!!!" );
while (1)
{
if (sw1 ==1) //<<<declare your main code here
ledr1 = 1;
else
ledr1 = 0;
if (sw1 ==0)
ledg1 = 1;
else
ledg1 = 0;
if (sw2 ==1)
ledr2 = 1;
else
ledr2 = 0;
if (sw2 ==0)
ledg2 = 1;
else
ledg2 = 0;
if (sw3 ==1)
ledr3 = 1;
else
ledr3 = 0;
if (sw3 ==0)
ledg3 = 1;
else
ledg3 = 0;
if (sw4 ==1)
ledr4 = 1;
else
ledr4 = 0;
if (sw4 ==0)
ledg4 = 1;
else
ledg4 = 0;
if (sw5 ==1)
ledr5 = 1;
else
ledr5 = 0;
if (sw5 ==0)
ledg5 = 1;
else
ledg5 = 0;
if (sw6 ==1)
ledr6 = 1;
else
ledr6 = 0;
if (sw6 ==0)
ledg6 = 1;
else
ledg6 = 0;
}
}
delay_ms(unsigned int x) // delay 1 ms
{
for(;x>0;x--);
{
T0CON=0b10010000; //Fosc 20MHz, Timer 0,16-bit mode, prescaler 1:2, use internal clock, increment on positive-edge
TMR0H=0xF6;
TMR0L=0x3C;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;
}
}
Last edited by a moderator: