/****************************************************************************************
; *
; FILENAME: LCD INTERFACING.C *
; DATE: 17/02/2011 *
; FILE VERSION: 1.0 *
; *
; AUTHOR: PARK CHENG WONG *
; DESCRIPTION: SHOW STUDENT NAME AND ID ON LCD *
; *
; *
;****************************************************************************************
;PIN USAGE
;
;PORTA BIT 0 //ENABLE
;PORTA BIT 1 //RS
;PORTA BIT 2 //RW
;PORTA BIT 3
;PORTA BIT 4
;PORTA BIT 5
;PORTA BIT 6
;PORTA BIT 7
;
;PORTB BIT 0
;PORTB BIT 1 //SWITCH
;PORTB BIT 2
;PORTB BIT 3
;PORTB BIT 4
;PORTB BIT 5
;PORTB BIT 6
;PORTB BIT 7
;
;PORTC BIT 0 //LCD
;PORTC BIT 1 //LCD
;PORTC BIT 2 //LCD
;PORTC BIT 3 //LCD
;PORTC BIT 4 //LCD
;PORTC BIT 5 //LCD
;PORTC BIT 6 //LCD
;PORTC BIT 7 //LCD
*/
cli
/***************************************************************************************/
//prototype procedures
void setupPIC (void);
void WriteString(const char *StringAdd, uns8 line, uns8 posn);
void main (void);
#pragma config |= 0x3fb1 // set up configure register
// assign names to port pins
bit SWITCH @ PORTB.1;
bit E @ PORTA.0;
bit RS @ PORTA.1;
bit RW @ PORTA.2;
//***************************************************************************************
// SETUP PROCEDURE *
//***************************************************************************************
//setup required options for PIC
//RECEIVES - nothing
//RETURNS - nothing
void setup(void)
{
PORTA=0; //set all o/ps to 0
PORTB=0;
PORTC=0;
TRISA = 0;
TRISB = 2; //set pinB 1 as input
TRISC = 0;
ADCON1 = 6; //configure ADC for all digital I/O
//***************************************************************************************
// PROGRAM SRART *
//***************************************************************************************
void main( void)
{
while(SWITCH==1);
while(SWITCH==0);
writestring('PARK CHENG WONG',0,0);
while(SWITCH==1);
while(SWITCH==0);
writestring('040739376',1,0);
while(SWITCH==1);
while(SWITCH==0);
clear (0x01)
cursor (0x02)
}
//***************************************************************************************
// DELAY PROCEDURE *
//***************************************************************************************
//time delay - miliseconds - uses TIMER 0
//RECEIVES - UNS16 number of miliseconds to delay
//RETURNS - nothing
void delay(uns16 milisec)
{ uns8 next = 0;
OPTION = 2; // prescaler divide TMR0 rate by 8
TMR0 = 2; // deduct 2*8 fixed instruction cycles delay
do
{
next += 125;
while (TMR0 != next) // 125 * 8 = 1000 (= 1 ms)
;
}while ( -- milisec !=0);
}
//***************************************************************************************
// SENDSTRING PROCEDURE *
//***************************************************************************************
//send an ascii string to the LCD
//send is placed at the cursor position received
//RECEIVES a pointer to the string, line number and line position
//RETURNS nothing
void WriteString(const char *StringAdd, uns8 line, uns8 posn)
{ char character;
//set 1st character position depending on the line number & position receired
if(lin==0)
send_byte(0x80 + posn,0); //set cursor position in line 0
else
send_byte(0xc0 + posn,0); //set cursor position in line 1
while(1)
{
character = *StringAdd; //get character from array
StringAdd++; //increment array address
if(character==0) //see if we have a zero-end of string
break; //if so get out of while loop
send_byte(character,1); //send character to LCD-mode=1
//student to write the send)byte procedure
delay(1); //wait 1mS
}
}