[SOLVED] Issues with 16x2 LCD Code using Hi-Tech PIC Compiler

Status
Not open for further replies.

Muhammad Akmal Wong

Newbie level 5
Joined
Feb 4, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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.


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:

Looked over the code. What type of LCD are you using ? 16 x 2 ? What brand ? Port D is defined for E and RS. Are you sending 8 data bits in parallel to it with Port C ? A schematic of the interface to the LCD might be helpful.
 

erm Fentrac its 16x2 LM016L i playing the E and RS on PORTBbits.RB4 and RB5 for E and RS sry for the wrong define. and i'm trying to use 8 data bits to port D which means D0 till D7 is connected to PORTD But right now i facing a new problem which is i'm using limit switch if i press the ledr1 is ON while the ledg1 is off else the ledg1 is ON
Code:
	if	(sw1 ==1)
			ledr1 = 1;
			else
			ledg1 = 1;
is the coding is wrong or my port have a problem?
 

In regards to your second question:
Your code shown on your original post: (comments added)


Code dot - [expand]
1
2
3
4
5
6
7
8
9
if  (sw1 == 1)           //<<<declare your main code here
    ledr1 = 1;                   // if sw1 == 1,  ledr1 is on
    else                               // else (if sw1 != 1), ledr1 is off 
    ledr1 = 0;
    
    if  (sw1 == 0)                 // if sw1 == 0, ledg1 is on
    ledg1 = 1;
    else                               // else (if sw1 != 0) ledg1 is off
    ledg1 = 0;


Would seem to be more correct than the second post. The second post does not appear to turn the LED's off.

Will submit a reply about the 16 x 2 display after reviewing it's data sheet.
 
Last edited by a moderator:

With regards to your LCD display.

The 2 functions you need to talk to the display are your sendData function, and the initializeLCD function, which is declared but not implemented.

Send data seems to have the elements needed. Set RS for command or Data, write the data to the correct port, bring E high, delay and then Low.

Before sending data to the display, it needs to be initialized. Use the initializeLDC funtion to do the following:

send the command hex 0x30 to the display three times using the sendData function. RS will be 0 to indicate it is a command. Delay 20 microseconds in between sending the command each time.
Next send a "set function" command. Look at the data sheet to see which bits in the command byte should be set. next send a "display on" command, delay 38 microseconds. Then send an "entry mode" command, delay 38 microseconds, then a "clear display" command. That completes the initializeLCD function.

Now you should be able to send your welcome message to the display.
 

I think your "delay_ms()" routine is wrong. I assume you intend setting up a 1mS delay using the timer and call it 'x' times to set a delay of 'x' mS.

At the moment you have a loop that executes 'x' times then calls a single 1mS timer delay.

Brian.
 

erm sir FenTrac i'm still begineer about coding i'm using MPLAB IDE v8.30 i dont know how to write lcd coding i just simply find other example and try to understand and about the datasheet i can understand but i dont know how to write the coding what i means is like the input i know how to write it example PORTBbits.RB0 and so on but for lcd i dont know to write it XD sry to make it difficult to understand after all i already update the coding below is my latest coding
Code:
//=============================================================================
// Filename: CodingOnGoing.c
//=============================================================================
#include <htc.h>                // Using Hi-Tech C v9.63 compiler, for different 

//=============================================================================
//	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.RB4
#define sw6			PORTBbits.RB5		//for switch

//=============================================================================
//	Main Program
//=============================================================================


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     

	                         
	while (1)
	{
	 
		{	
			if	(sw1 ==1)
			ledr1 = 1;
		else
			ledg1 = 1;
			ledr1 = 0;
		}
		{	
			if	(sw1 ==0)
			ledg1 = 1;
		else
			ledr1 = 1;
			ledg1 = 0;
		}
		{	
			if	(sw2 ==1)
			ledr2 = 1;
		else
			ledg2 = 1;
			ledr2 = 0;
		}
		{	
			if	(sw2 ==0)
			ledg2 = 1;
		else
			ledr2 = 1;
			ledg2 = 0;
		}
		{	
			if	(sw3 ==1)
			ledr3 = 1;
		else
			ledg3 = 1;
			ledr3 = 0;
		}
		{	
			if	(sw3 ==0)
			ledg3 = 1;
		else
			ledr3 = 1;
			ledg3 = 0;
		}
		{	
			if	(sw4 ==1)
			ledr4 = 1;
		else
			ledg4 = 1;
			ledr4 = 0;
		}
		{	
			if	(sw4 ==0)
			ledg4 = 1;
		else
			ledr4 = 1;
			ledg4 = 0;
		}
		{	
			if	(sw5 ==1)
			ledr5 = 1;
		else
			ledg5 = 1;
			ledr5 = 0;
		}
		{	
			if	(sw5 ==0)
			ledg5 = 1;
		else
			ledr5 = 1;
			ledg5 = 0;
		}
		{	
			if	(sw6 ==1)
			ledr6 = 1;
		else
			ledg6 = 1;
			ledr6 = 0;
		}
		{	
			if	(sw6 ==0)
			ledg6 = 1;
		else
			ledr6 = 1;
			ledg6 = 0;
		}
		
	}
}
 

Mr/Mrs Betwixt erm about the delay routine i kindly abit dizzy and forgot how to calculate the delay ms and forgot to change it i'm using 4MHz crystal oscillator i dont know how to write the delay routine.
 

It's simple typing error, it would work properly if you removed the ';' at the end of the loop instruction:
Code:
delay_ms(unsigned int x)    // delay 1 ms
{
    for(;x>0;x--);  [COLOR=#FF0000]<<< remove the semicolon at the end of this line[/COLOR]
        {
        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;
        }
}

The semicolon terminates the instruction so you would simply count 'x' down to zero then run the timer code once. I think what you intended to do was run the timer code 'x' times.

Brian.
 

thanks for helping for the delay routine now i need thinking how to do/write lcd coding i dont even know one thing about it just know how to make input output dat's all cause i learn lcd coding in assembly but i need do my program in c language ... dizzy to solve this problem and i dont know how to get the reg51.h lcd.h lcd.c compillar

- - - Updated - - -

FYI this is my latest coding, hope u guys can help me find the error i already try my best to fix it but still have little problem when i'm compile it
Code:
//=============================================================================
// Filename: CodingOnGoing.c
//=============================================================================
#include <htc.h>                // Using Hi-Tech C v9.63 compiler, for different 
#include <pic.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.RB4
#define sw6			PORTBbits.RB5		//for switch

#define RS RB6
#define EN RB7
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7

#define _XTAL_FREQ 8000000
//=============================================================================
//LCD
//=============================================================================
#include "lcd.h"
//=============================================================================
//	Main Program
//=============================================================================


void main (void) 
{	
    int i;
	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     
	Lcd8_Init();
	
	while(1)
  	{
    Lcd8_Set_Cursor(1,1);
    Lcd8_Write_String("Welcome");
    for(i=0;i<15;i++)
    {
      __delay_ms(1000);
      Lcd8_Shift_Left();
    }
    for(i=0;i<15;i++)
    {
      __delay_ms(1000);
      Lcd8_Shift_Right();
    }
    Lcd8_Clear();
    Lcd8_Set_Cursor(2,1);
    Lcd8_Write_Char('e');
    Lcd8_Write_Char('S');
    __delay_ms(2000);
  	}
	                         
	while (1)
	{
	 
		{	
			if	(sw1 ==1)
			ledr1 = 1;
		else
			ledg1 = 1;
			ledr1 = 0;
		}
		{	
			if	(sw1 ==0)
			ledg1 = 1;
		else
			ledr1 = 1;
			ledg1 = 0;
		}
		{	
			if	(sw2 ==1)
			ledr2 = 1;
		else
			ledg2 = 1;
			ledr2 = 0;
		}
		{	
			if	(sw2 ==0)
			ledg2 = 1;
		else
			ledr2 = 1;
			ledg2 = 0;
		}
		{	
			if	(sw3 ==1)
			ledr3 = 1;
		else
			ledg3 = 1;
			ledr3 = 0;
		}
		{	
			if	(sw3 ==0)
			ledg3 = 1;
		else
			ledr3 = 1;
			ledg3 = 0;
		}
		{	
			if	(sw4 ==1)
			ledr4 = 1;
		else
			ledg4 = 1;
			ledr4 = 0;
		}
		{	
			if	(sw4 ==0)
			ledg4 = 1;
		else
			ledr4 = 1;
			ledg4 = 0;
		}
		{	
			if	(sw5 ==1)
			ledr5 = 1;
		else
			ledg5 = 1;
			ledr5 = 0;
		}
		{	
			if	(sw5 ==0)
			ledg5 = 1;
		else
			ledr5 = 1;
			ledg5 = 0;
		}
		{	
			if	(sw6 ==1)
			ledr6 = 1;
		else
			ledg6 = 1;
			ledr6 = 0;
		}
		{	
			if	(sw6 ==0)
			ledg6 = 1;
		else
			ledr6 = 1;
			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;
		}

}
 

Looked over your new code that uses the LCD library. I'm not able to test your code, as I don't have a PIC18F4550 or a display hooked to one to test and
I use sdcc for C on pics not Hi-tech C.

I made some suggestions in the code below. It looks like the first "while loop" would run forever and never get to the second while loop to check the switches. The second while loop will also run forever, but maybe this is what you want, - to check the switches forever. The brackets were not placed correctly on the if - else
statements for checking switches, so these are changed in the attached code below.
Did your code compile without errors ? Did it display anything on your display ?
I added a comment above main() with a link to a website on the Hi-tech C lcd library.



Code:
/=============================================================================
// Filename: CodingOnGoing.c
//=============================================================================
#include <htc.h>                // Using Hi-Tech C v9.63 compiler, for different 
#include <pic.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.RB4
#define sw6		PORTBbits.RB5		//for switch

#define RS RB6
#define EN RB7
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7

#define _XTAL_FREQ 8000000
//=============================================================================
//LCD
//=============================================================================
#include "lcd.h"
//=============================================================================
//	Main Program
//=============================================================================


void main (void) 
{	
    int i;
	
        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     
	 
        Lcd8_Init();                // this sends the initialization to the lcd using 8 bits
	
	//  while(1)                // Get rid of the while loop 
  	//  {                         // it would run forever and not go to switches

          Lcd8_Set_Cursor(1,1);     // this sets the cursor to position 1, 1
          
          Lcd8_Write_String("Welcome");  // this writes welcome
         
          for(i=0;i<15;i++)        // this delays for 15 seconds by calling a 1000 millisecond
            {                             // delay 15 times
            __delay_ms(1000);    // does delay_ms need the 2 underscores in front of it ?
            Lcd8_Shift_Left();      // shift the display left 15 times ????
            }
          for(i=0;i<15;i++)
            {
            __delay_ms(1000);
            Lcd8_Shift_Right();     //  shift the display right 15 times ????
            }
          Lcd8_Clear();              
          Lcd8_Set_Cursor(2,1);     // cursor is set to position 2, 1
          Lcd8_Write_Char('e');     // write 'e' to the display
          Lcd8_Write_Char('S');     // write 'S' to the display
           __delay_ms(2000);        // delay 2 seconds
  	  
        }                 
	                         
	  while(1)                  // now going into a while loop forever
	    {
	 
		// {	                //  this bracket is not needed here so commented out
		if	(sw1 ==1)
			ledr1 = 1;
		else 
                    {                   // this bracket added since there is more than 1 thing to                         
			ledg1 = 1;  //  do for the else statement
			ledr1 = 0;
		     }
		
		if  (sw1 ==0)
			ledg1 = 1;
		else
                     {  
			ledr1 = 1;
			ledg1 = 0;
		      }
			
		if	(sw2 ==1)
			ledr2 = 1;
		else
                     {
			ledg2 = 1;
			ledr2 = 0;
		     }
			
	        if  (sw2 ==0)
			ledg2 = 1;
		else
                     {
			ledr2 = 1;
			ledg2 = 0;
		      }
			
		if  (sw3 ==1)
			ledr3 = 1;
		else
                     {
			ledg3 = 1;
			ledr3 = 0;
	  	     }
		  	
		if  (sw3 ==0)
			ledg3 = 1;
		else
                    {
			ledr3 = 1;
			ledg3 = 0;
		     }
			
		 if	(sw4 ==1)
			ledr4 = 1;
		 else
                     {
			ledg4 = 1;
			ledr4 = 0;
		      }
			
		if    (sw4 ==0)
			ledg4 = 1;
		else
                     {
			ledr4 = 1;
			ledg4 = 0;
		      }
			
		if (sw5 ==1)
			ledr5 = 1;
		else
		     {	
                        ledg5 = 1;
			ledr5 = 0;
		     }
			
		if	(sw5 ==0)
			ledg5 = 1;
		else
                     {
			ledr5 = 1;
			ledg5 = 0;
		      }
			
		if  (sw6 ==1)
			ledr6 = 1;
		else
                      {
			ledg6 = 1;
			ledr6 = 0;
		       }
			
		if (sw6 ==0)
			ledg6 = 1;
		else
                       {
			ledr6 = 1;
			ledg6 = 0;
		       }
		
	}  // end of while loop
}  // end of main

delay_ms(unsigned int x)	 // delay 1 ms
{
	for(x = x ;x > 0; x--)    // added  x = x    here
		{
		T0CON=0b10010000;     //Fosc 20MHz, Timer 0,16-bit mode, prescaler 1:2,      
		TMR0H=0xF6;
		TMR0L=0x3C;
		T0CONbits.TMR0ON=1;
		while(INTCONbits.TMR0IF == 0);
		T0CONbits.TMR0ON=0;
		INTCONbits.TMR0IF=0;
		}

}
 

erm i already fix it right, here some fileView attachment On going.zip i dont know how to upload zip file may i have ur email sir? so dat i can send u my zip file kindly still new in this forum doest know how to upload zip file
here some my update code i recent changed too just awhile
Code:
//=============================================================================
// Filename: CodingOnGoing.c
//=============================================================================
#include <htc.h>                // Using Hi-Tech C v9.63 compiler, for different 
#include "lcd.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.RB4
#define sw6			PORTBbits.RB5		//for switch

#define RS RB6
#define EN RB7
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7

#define _XTAL_FREQ 8000000
//=============================================================================
//LCD
//=============================================================================

//=============================================================================
//	Main Program
//=============================================================================


void main (void) 
{	
    int i;
	TRISA = 0;
	TRISB = 1;
	TRISC = 0;
	TRISD = 0;
	TRISE = 0;
	PORTA = 0;
	PORTB = 0;
	PORTC = 0;
	PORTD = 0;
	PORTE = 0;
	ADCON1=0b00001111;          //<<<declare input and output pin here     
	
   
	                         
	while (1)
	{

        Lcd8_Init();
        Lcd8_Set_Cursor(1,1);
        Lcd8_Write_String("Welcome");
        for(i=0;i<15;i++)
        {
        delay_ms(1000);
        Lcd8_Shift_Left();
        }
	 
			
			if	(sw1 ==1)
			ledr1 = 1;
	     	else
			ledg1 = 1;
			ledr1 = 0;
		
			
			if	(sw1 ==0)
			ledg1 = 1;
		    else
			ledr1 = 1;
			ledg1 = 0;
		
			
			if	(sw2 ==1)
			ledr2 = 1;
		    else
			ledg2 = 1;
			ledr2 = 0;
		
		
			if	(sw2 ==0)
			ledg2 = 1;
		    else
			ledr2 = 1;
			ledg2 = 0;
		
			
			if	(sw3 ==1)
			ledr3 = 1;
		    else
			ledg3 = 1;
			ledr3 = 0;
		
			
			if	(sw3 ==0)
			ledg3 = 1;
		    else
			ledr3 = 1;
			ledg3 = 0;
		
			
			if	(sw4 ==1)
			ledr4 = 1;
		    else
			ledg4 = 1;
			ledr4 = 0;
		
			
			if	(sw4 ==0)
			ledg4 = 1;
		    else
			ledr4 = 1;
			ledg4 = 0;
		
			
			if	(sw5 ==1)
			ledr5 = 1;
		    else
			ledg5 = 1;
			ledr5 = 0;
		
			
			if	(sw5 ==0)
			ledg5 = 1;
		    else
			ledr5 = 1;
			ledg5 = 0;
		
			
	     	if	(sw6 ==1)
			ledr6 = 1;
		    else
			ledg6 = 1;
			ledr6 = 0;
		
			
			if	(sw6 ==0)
			ledg6 = 1;
		    else
			ledr6 = 1;
			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;
		}

}
i still have problem with the lcd.h where inside the lcd.h include inttypes.h cannot be detect by mplab v8.30. finding solution how to solve it right now. hope sir can help me =) thanks for guiding me for so long sry to take ur time sir.

- - - updated - - -

Error [141] C:\Users\Dell\Documents\On going\lcd.h; 40.21 can't open include file "inttypes.h": No such file or directory
(908) exit status = 1


having this issue when compile the file sir i already add the header in the header file
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…