LCD Test C source
Jump to navigation
Jump to search
Rugby Clock - Debug Information - LCD Test C Source
<source lang="c"> /* Test program to check LCD display connections from a PIC 16F873 */ /* Part of the rugby clock project. - Tim Styles 25/4/11 */ /* http://www.timstyles.me.uk/wiki/Rugby_Clock */ /* This version is written to use the Hi-Tech lite (free) compiler */
- include <htc.h>
/* Configure with crystal oscillator and no low-voltage programming */ __CONFIG(FOSC_XT & LVP_OFF);
/* Wait, pulse the Enable line high for 20 us and wait again */ clk() {
_delay( 40 ); RB1 = 1; /* Enable line = high */ _delay( 20 ); /* Wait 20 microseconds (with 4MHz clock) */ RB1 = 0; /* Enable line = low */ _delay( 40 );
}
/* Minimum configuration for LCD display (set cursor and turn on) */ /* Then send the characters 'Hello World!' and wait for the watchdog */ /* timer causes a reset */ void main() {
TRISB = 0b00000000; TRISC = 0b00000000;
RB2 = 0; /* Read / Write line = WRITE */ RB3 = 0; /* Register Select line = command */ PORTC = 0x38; clk(); /* Small cursor, two lines, 8 bit interface */ PORTC = 0x0C; clk(); /* Turn on display, no cursor */
RB3 = 1; /* Register Select line = data */ PORTC = 'H'; clk(); PORTC = 'e'; clk(); PORTC = 'l'; clk(); PORTC = 'l'; clk(); PORTC = 'o'; clk(); PORTC = ' '; clk(); PORTC = 'W'; clk(); PORTC = 'o'; clk(); PORTC = 'r'; clk(); PORTC = 'l'; clk(); PORTC = 'd'; clk(); PORTC = '!'; clk();
while(1); /* Wait indefinitely (until watchdog reset) */
} </source>