152 lines
4.7 KiB
C
152 lines
4.7 KiB
C
#include <system.h>
|
|
#include "lcd.h"
|
|
#include "util.h"
|
|
/*******************************************************************
|
|
http://forum.sparkfun.com/viewtopic.php?p=33650
|
|
EXAMPLE:
|
|
|
|
const unsigned char LCD_CHAR_BAR1[] = {
|
|
0x1F, // ---11111
|
|
0x10, // ---10000
|
|
0x10, // ---10000
|
|
0x10, // ---10000
|
|
0x10, // ---10000
|
|
0x10, // ---10000
|
|
0x10, // ---10000
|
|
0x1F // ---11111
|
|
};
|
|
|
|
LCD_Init();
|
|
LCDCls();
|
|
x = 0;
|
|
LCD_DefineChar (1, LCD_CHAR_BAR1);
|
|
LCD_DefineChar (2, LCD_CHAR_BAR3);
|
|
LCD_DefineChar (3, LCD_CHAR_BAR2);
|
|
LCD_DefineChar (4, LCD_CHAR_BAR4);
|
|
LCD_DefineChar (5, LCD_CHAR_BAR5);
|
|
|
|
LCD_SetPosition ( LINE_1 + 0 );
|
|
printf("\1\5\2 RF Terminal", 0, LCD);
|
|
*****************************************************************/
|
|
|
|
/*******************************************************************/
|
|
// Prototypes
|
|
/*******************************************************************/
|
|
void lcd_init ( void ){
|
|
lcd_setData (0x00);
|
|
delay_ms (200); /* wait enough time after Vdd rise */
|
|
LCD_RS = 0;
|
|
lcd_setData (0x03); /* init with specific nibbles to start 4-bit mode */
|
|
lcd_pulseEnable();
|
|
lcd_pulseEnable();
|
|
lcd_pulseEnable();
|
|
lcd_setData (0x02); /* set 4-bit interface */
|
|
lcd_pulseEnable(); /* send dual nibbles hereafter, MSN first */
|
|
lcd_putChar (0x2C, CMD);/* function set (all lines, 5x7 characters) */
|
|
lcd_putChar (0x0C, CMD);/* display ON, cursor off, no blink */
|
|
lcd_putChar (0x01, CMD);/* clear display */
|
|
lcd_putChar (0x06, CMD);/* entry mode set, increment & scroll left */
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_setPosition ( unsigned char cX ){
|
|
/* this subroutine works specifically for 4-bit Port A */
|
|
lcd_setData ((cX >> 4) | 0x08);
|
|
lcd_pulseEnable();
|
|
lcd_setData (cX);//(swap(cX));
|
|
lcd_pulseEnable();
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_putChar (unsigned char cX, unsigned char cmd){
|
|
// this subroutine works specifically for 4-bit Port A
|
|
if (cmd == DATA) LCD_RS = 1;// data?
|
|
lcd_setData (cX >> 4); // Send high nibble
|
|
lcd_pulseEnable();
|
|
lcd_setData (cX); // Send low nibble
|
|
lcd_pulseEnable();
|
|
if (cmd == DATA) LCD_RS = 0;
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_pulseEnable (void){
|
|
LCD_EN = 1;
|
|
delay_us (5);
|
|
LCD_EN = 0;
|
|
delay_us (5);
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_setData (unsigned char cX){
|
|
LCD_D0 = cX.0;
|
|
LCD_D1 = cX.1;
|
|
LCD_D2 = cX.2;
|
|
LCD_D3 = cX.3;
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_cls(void){
|
|
lcd_putChar(CLEAR_DISP, CMD);
|
|
}
|
|
|
|
/*******************************************************************/
|
|
/*
|
|
** LCD_DefineCharacter: Define dot pattern for user-defined character.
|
|
**
|
|
** inputs: address = address of character (0x00-0x07)
|
|
** pattern = pointer to 8-byte array containing the dot pattern
|
|
*/
|
|
void lcd_defineChar (unsigned char address, const unsigned char *pattern){
|
|
char i, addr;
|
|
|
|
addr = (address << 3);
|
|
lcd_putChar(0x40 + addr, CMD);
|
|
for (i=0; i<8; i++) {
|
|
lcd_putChar(*pattern++, DATA);
|
|
}
|
|
}
|
|
|
|
/*******************************************************************/
|
|
/*******************************************************************/
|
|
|
|
void lcd_putc (char ch){ // Char to send thru rs-232
|
|
lcd_putChar (ch, DATA);
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_puts (const char *str){ // String to send thru rs-232
|
|
char ps;
|
|
ps = *str; // Pointer to the string start in ps
|
|
while( ps>0 ){ // While not end...
|
|
str++; // Increment pointer
|
|
if (ps== 0) break; // If end of string... finish.
|
|
lcd_putc (ps);
|
|
ps = *str; // Point to new char
|
|
}
|
|
}
|
|
|
|
/*******************************************************************/
|
|
void lcd_putd(int decimal){ // prints a decimal number
|
|
unsigned char decimal_output[5];
|
|
unsigned char m, temp;
|
|
//Print negative sign and take 2's compliment
|
|
if(decimal < 0){
|
|
lcd_putc ('-');
|
|
decimal *= -1;
|
|
}
|
|
if (decimal == 0)
|
|
lcd_putc ('0');
|
|
else{
|
|
//Divide number by a series of 10s
|
|
for(m = 4 ; decimal > 0 ; m--){
|
|
temp = decimal % (unsigned int)10;
|
|
decimal_output[m] = temp;
|
|
decimal = decimal / (unsigned int)10;
|
|
}
|
|
|
|
for(m++ ; m < 5 ; m++)
|
|
lcd_putc(bin2Hex(decimal_output[m]));
|
|
}
|
|
}
|
|
|
|
/*******************************************************************/
|