#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define _XTAL_FREQ 1000000
#include <xc.h>
#define LCD_PORTB PORTB
#define RS RB0
#define EN RB1
void Strobe (void)
{
EN = 1;
__delay_us(1);
EN = 0;
}
void LCD_cmd( unsigned char cmd)
{
RS = 0;
__delay_ms(1);
LCD_PORTB = (cmd & 0xf0) ;
Strobe();
LCD_PORTB = (cmd << 4 );
Strobe();
}
void LCD_data( unsigned char data)
{
RS = 1;
__delay_ms(1);
LCD_PORTB |= (data & 0xf0);
Strobe();
LCD_PORTB |= (data << 4 );
Strobe();
}
void LCD_init()
{
__delay_ms(20);
LCD_cmd(0x38);
__delay_ms(4);
LCD_cmd(0x38);
__delay_ms(10);
// LCD_cmd(0x38); // Power on Initilization
LCD_cmd(0x28); /* 4bit mode */
LCD_cmd(0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_cmd(0x0C); /* Display ON Cursor OFF */
LCD_cmd(0x06); /* Auto Increment cursor */
}
void string(const char *ptr)
{
while (*ptr)
{
LCD_data(*ptr++);
}
}
void main()
{
TRISB =0;
TRISD =0;
LCD_init();
LCD_cmd(0x80);
//string("HELLO WORLD");
// LINE2;
string("IT IS WORKING:-)");
while(1);
return ;
}
Sir ,What should one figure out from the above picture ? Are you considering that removing the whole wire from the VSS pin at the LCD module would solve the missing net connection ?
--- Updated ---
In addition, got rid of the VEE biasing connection; I guess it should not be feft floating.
Are you using real hardware or a simulator?In proteus simulation its worked .......
The pot V wants to range from Vss to Vdd, at least thats what I am doing on my baords and works just fine toAre you using real hardware or a simulator?
Also what is not working? If it is simply no characters visible, then try setting up the 'contrast' voltage and turning it so that you see the blank rectangles and then turn it back a little (until the rectangles are very faint or just not visible). A common mistake is to have the contract set so low that the character 'dots' are not lit up.
Also @danadakk: the wiring around the variable resistor is wrong - no connection to Vss.
Susan
Did you understand why |= can't work in this place? I wonder how you arrived at this code? Did you invent it on your own, or is it copy-and-paste fault?@betwixt , where does the port clear inside the Functions ? (tried inside the function by initlizing with zero but not worked )
Sir Nothing done there by ORing i too much time tired by rediting the code so ,i forget to remove that OR operator .Did you understand why |= can't work in this place? I wonder how you arrived at this code? Did you invent it on your own, or is it copy-and-paste fault?
RS = 0;
__delay_ms(1);
LCD_PORTB = (cmd & 0xf0) ;
Strobe();
LCD_PORTB = (cmd << 4 );
Strobe();
void LCD_data( unsigned char data)
{
__delay_ms(1);
LCD_PORTB = (data & 0xf0);
RS = 1;
Strobe();
LCD_PORTB = (data << 4 );
RS = 1;
Strobe();
}
void LCD_data( unsigned char data)
{
__delay_ms(1);
LCD_PORTB = (data & 0xf0) | 1;
Strobe();
LCD_PORTB = (data << 4 ) | 1;
Strobe();
}
changed as you said but not worked sir ,You should try to understand what you are doing here.
RS is also located in PORTB, so the correct LCD_DATA function could like this
Code:void LCD_data( unsigned char data) { __delay_ms(1); LCD_PORTB = (data & 0xf0); RS = 1; Strobe(); LCD_PORTB = (data << 4 ); RS = 1; Strobe(); }
or shorter
Code:void LCD_data( unsigned char data) { __delay_ms(1); LCD_PORTB = (data & 0xf0) | 1; Strobe(); LCD_PORTB = (data << 4 ) | 1; Strobe(); }
Show us the whole code again now you have implemented the changes we suggested.
Brian.
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#define _XTAL_FREQ 4000000
#define RS PORTBbits.RB0
#define EN PORTBbits.RB1
void Strobe (void)
{
EN = 1;
__delay_us(2);
EN = 0;
}
void LCD_cmd( unsigned char cmd)
{
PORTB = 0x00;
PORTB = (cmd & 0xf0) ;
RS = 0;
Strobe();
PORTB = (cmd << 4 )&0xf0;
Strobe();
}
void LCD_data( unsigned char data)
{ PORTB = 0x00;
PORTB = (data & 0xf0) | 1;
Strobe();
PORTB = (data << 4 ) | 1;
Strobe();
}
void LCD_init()
{
__delay_ms(20);
LCD_cmd(0x38);
__delay_ms(4);
LCD_cmd(0x38);
__delay_ms(2);
LCD_cmd(0x28); /* 4bit mode */
LCD_cmd(0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_cmd(0x0C); /* Display ON Cursor OFF */
LCD_cmd(0x06); /* Auto Increment cursor */
}
void string(const char *ptr)
{
while (*ptr)
{
LCD_data(*ptr++);
}
}
void main()
{
TRISB =0;
PORTB = 0X00;
LCD_init();
while(1)
{
string("HELLO WORLD");
// LINE2;
string("Testing)");
//LCD_data(1);
}
return ;
}
PORTB = 0x00;
PORTB = (data & 0xf0) | 1;
PORTB = 0x00;
NOP;
PORTB = (data & 0xf0) | 1;
PORTB = (data & 0xf0) | 1;
Strobe();
PORTB = (data << 4 ) | 1;
Strobe();
void Strobe (void)
{
EN = 1;
__delay_us(2);
EN = 0;
__delay_us(2);
}
Code C - [expand] 1 LCD_cmd(0x38);
PORTB = (cmd & 0xf0) ;
PORTB = (cmd << 4 )&0xf0;
#define LCD_D0 RB4
#define LCD_D1 RB5
#define LCD_D2 RB6
#define LCD_D3 RB7
LCD_write(char data)
{
if(data & 0x01) LCD_D0 = 1 else LCD_D0 = 0;
if(data & 0x02) LCD_D1 = 1 else LCD_D1 = 0;
if(data & 0x04) LCD_D2 = 1 else LCD_D2 = 0;
if(data & 0x08) LCD_D3 = 1 else LCD_D3 = 0;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?