/* io.c * * Copyright (c) 2003-2004 Susan Cotterell. * Permission to copy is granted provided that this header remains * intact. This software is provided with no warranties. * * Version : 1.0 * * 8-Bit LCD Interface * */ /*-------------------------------------------------------------------------*/ #include #include "io.h" #include "delay.h" /*-------------------------------------------------------------------------*/ #define DATA_BUS PORTB #define RS RA2 #define E RA3 #define RS_BIT 2 #define E_BIT 3 /*-------------------------------------------------------------------------*/ unsigned char tempA = 0x00; /*-------------------------------------------------------------------------*/ void EnableLCD(void) { bitclr(tempA, PORTA, RS_BIT); DelayUs(1); //RS = 0 bitset(tempA, PORTA, E_BIT); DelayUs(1); //E = 1 bitclr(tempA, PORTA, E_BIT); DelayUs(1); //E = 0 } /*-------------------------------------------------------------------------*/ void EnableLCD2(void) { bitset(tempA, PORTA, RS_BIT); DelayUs(1); bitset(tempA, PORTA, E_BIT); DelayUs(1); bitclr(tempA, PORTA, E_BIT); DelayUs(1); } /*-------------------------------------------------------------------------*/ void InitIO(void) { DATA_BUS=0x38; EnableLCD(); DelayMs(5); DATA_BUS=0x38; EnableLCD(); DelayUs(100); DATA_BUS=0x38; EnableLCD(); DelayUs(100); DATA_BUS=0x38; EnableLCD(); DelayUs(100); DATA_BUS=0x01; EnableLCD(); DelayMs(2); DATA_BUS=0x0d; EnableLCD(); DelayUs(40); DATA_BUS=0x06; EnableLCD(); DelayUs(40); } /*-------------------------------------------------------------------------*/ void ClearScreen(void) { DATA_BUS=0x01; EnableLCD(); DelayMs(2); } /*-------------------------------------------------------------------------*/ void GotoXY(unsigned char r, unsigned char c) { DATA_BUS=0x02; EnableLCD(); DelayMs(2); for(r=r*40+c, c=0; c