PIC16F684 output to LCD - help needed

Status
Not open for further replies.

goowiz

Newbie level 2
Joined
Jun 26, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,292
pic16f684 lcd interface

Hi, I am trying to output numbers to a samsung UC-20102-GNARS one line 20 character lcd display from a PIC16f684 microcontroller.
I'm having some trouble... I have things wired as follows according to pin #:

PIC ------------ LCD
14 ------------- GND
13
12
11
10 (C0) -------- D4
9 (C1) --------- D5
8 (C2) --------- D6
7 (C3) --------- D7
6
5
4
3 (A4) --------- RS
2 (A5) --------- Enable
1 --------------- +5v

Here's my code:
Code:
#include <Temp Sensor.h>
#include <math.h>

#define ENABLE PIN_A5
#define RS PIN_A4
#define LCD_TYPE 1

// Function/Global Variable Delcaration
void Initialize(void);
void InitLCD(void);
void lcd_send_nibble(char c);
void lcd_send_data(char c);
void lcd_send_command(char command);
int i;

void main()
{
	SET_TRIS_A(0x01);
	
	setup_adc_ports(sAN0|VSS_VDD);
	setup_adc(ADC_CLOCK_INTERNAL);
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
	setup_timer_1(T1_DISABLED);
	setup_timer_2(T2_DISABLED,0,1);
	setup_comparator(NC_NC_NC_NC);
	setup_vref(FALSE);
	setup_oscillator(OSC_INTRC);
		
	InitLCD();


}


void InitLCD(void)
{
	
	
	// Initialize LCD
	output_low(ENABLE);			// Disable LCD
	delay_ms(50);				// Delay for 50ms
	
	SET_TRIS_C(0x00);			// All C ports set to output
	delay_ms(15);				// Delay for 15ms
		
	for(i = 1; i <= 3 ; ++i)
	{
		output_low(RS);			// Set LCD for instruction set
		output_c(3);			//
		output_high(ENABLE);	        // Enable LCD
		delay_us(5);			// Delay 5us
		output_low(ENABLE);		// Disable LCD
		delay_ms(5);			// Delay 5ms
	}
	
	lcd_send_nibble(3);			//
	
	lcd_send_command(0x20);		// Function Set:
							// 4bit data length
							// 1 Line
							// 5 x 7 Dot Format
								
	lcd_send_command(0x0F);		// Display ON/OFF Control:
							// Display ON
							// Cursor ON
							// Blink ON
	
	lcd_send_command(0x01);		// Display Clear
	
	lcd_send_command(0x05);		// Entry Mode Set:
							// Decrement one
							// Yes Shift
	
	lcd_send_data(0x52);		// "R"
	lcd_send_data(0x45);		// "E"
	lcd_send_data(0x41);		// "A"
	lcd_send_data(0x44);		// "D"
	lcd_send_data(0x59);		// "Y"
}

void lcd_send_nibble( char c ) 
{
	output_c(c);			// Output character to LCD
	output_high(ENABLE);		// Enable LCD
	delay_us(5);			// Delay 5us
	output_low(ENABLE);		// Disable LCD
}
	
void lcd_send_command(char command)
{
	delay_ms(5);						// Delay 5ms
	output_low(RS);						// Set LCD for instruction set
	lcd_send_nibble(command >> 4);		// Send high bits
	lcd_send_nibble(command & 0x0F);	        // Send low bits
}

void lcd_send_data( char c) 
{
	delay_ms(5);					// Delay 5ms
	output_high(RS);				// Set LCD for data set
	lcd_send_nibble(c >> 4);			// Send high bits
	lcd_send_nibble(c & 0x0F);			// Send low bits
}

As of now, the LCD will power up, but the whole line just shows a black box.
If anyone can help I'd greatly appreciate it. Thanks.
 

string output to lcd in c

bump
 

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…