Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD-PIC problem- Hitech c

Status
Not open for further replies.

Milead

Newbie level 5
Joined
Sep 13, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
yesterday i posted a similar problem with Mikroc and i managed to solve it.
today im facing the same problem in Hitech.
i only see black squares on the first row.
im using the hitech example code, but my code uses a single "port(B)".
PIC16f88-(i took care of config bits not in the code, but by going to Configure>Configuration Bits) Oscillator is set to HS.
code works fine in simulation (ISIS 7)

PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
PORTB bit 4 is connected to the LCD RS input (register select)
PORTB bit 5 is connected to the LCD EN bit (enable)

LCD.C:
#define _XTAL_FREQ 4000000


#include <htc.h>
#include "lcd.h"

#define LCD_RS RB4
#define LCD_RW RB6
#define LCD_EN RB5

#define LCD_DATA PORTB

#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

int control_store;

void
lcd_write(unsigned char c)
{
__delay_us(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F )^control_store;
LCD_STROBE();
LCD_DATA = ( c & 0x0F )^control_store;
LCD_STROBE();
}

/*
* Clear and home the LCD
*/

void
lcd_clear(void)
{
LCD_RS = 0;
control_store=PORTB & 0xF0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
control_store=PORTB & 0xF0;
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(char c)
{
LCD_RS = 1; // write characters
control_store=PORTB & 0xF0;
lcd_write( c );
}


/*
* Go to the specified position
*/

void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
control_store=PORTB & 0xF0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;
ANSEL = 0x00;
ADCON1 = 0x06; // Disable analog pins on PORTA
ADCON0 = 0x06;

init_value = 0x3;
TRISA=0;
TRISB=0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
control_store=PORTB & 0xF0;
__delay_ms(20); // wait 15mSec after power applied,
LCD_DATA = init_value^control_store;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2^control_store; // Four bit mode
LCD_STROBE();

lcd_write(0x28); // Set interface length
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}

Main:
#include <htc.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
void
main(void)
{
ANSEL = 0x00;
ADCON1 = 0x06; // Disable analog pins on PORTA
ADCON0 = 0x06;
__delay_ms(100);
lcd_init();
__delay_ms(100);
lcd_goto(0); // select first line
lcd_puts("12345678");
lcd_goto(0x40); // Select second line
lcd_puts("Hello world");

for(;;);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top