Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# spyglass.c

Go to the documentation of this file.

    00001 /*! \file spyglass.c \brief Spyglass Control Panel UI Board Driver. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'spyglass.c'
    00005 // Title        : Spyglass Control Panel UI Board Driver
    00006 // Author       : Pascal Stang - Copyright (C) 2005
    00007 // Created      : 7/20/2005
    00008 // Revised      : 7/23/2005
    00009 // Version      : 0.9
    00010 // Target MCU   : Atmel AVR series
    00011 // Editor Tabs  : 4
    00012 //
    00013 // This code is distributed under the GNU Public License
    00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00015 //
    00016 //*****************************************************************************
    00017
    00018
    00019 #include "global.h"
    00020 #include "rprintf.h"
    00021 #include "timer.h"
    00022 #include "i2c.h"
    00023 #include "spyglass.h"
    00024
    00025 #include "lcd.h"
    00026
    00027 u08 PcfCtrlData;
    00028
    00029 u08 pcf8574Write(u08 nodeAddr, u08 data)
    00030 {
    00031     // write data
    00032     return i2cMasterSendNI(PCF8574_I2C_BASE_ADDR+(nodeAddr<<1), 1, &data);
    00033 }
    00034
    00035 u08 pcf8574Read(u08 nodeAddr)
    00036 {
    00037     u08 data;
    00038     i2cMasterReceiveNI(PCF8574_I2C_BASE_ADDR+(nodeAddr<<1), 1, &data);
    00039     return data;
    00040 }
    00041
    00042 void spyglassInit(void)
    00043 {
    00044     i2cInit();
    00045     i2cSetBitrate(100);
    00046     PcfCtrlData = (SPYGLASS_LED0 | SPYGLASS_LED1 | SPYGLASS_BEEPER);
    00047     spyglassSetLeds(0);
    00048     spyglassSetBeeper(0);
    00049 }
    00050
    00051 u08 spyglassGetPushbuttons(void)
    00052 {
    00053     return ~pcf8574Read(PCF_NODE_BUTTONS);
    00054 }
    00055
    00056 void spyglassSetLeds(u08 leds)
    00057 {
    00058     PcfCtrlData = (PcfCtrlData|0x03) & ~(leds&0x03);
    00059     pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
    00060 }
    00061
    00062 void spyglassSetBeeper(u08 state)
    00063 {
    00064     if(state)
    00065         PcfCtrlData &=~SPYGLASS_BEEPER;     // beeper on
    00066     else
    00067         PcfCtrlData |= SPYGLASS_BEEPER;     // beeper off
    00068     pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
    00069 }
    00070
    00071 u08 spyglassSetLcdContrast(u08 contrast)
    00072 {
    00073     u08 data[2];
    00074     data[0] = 0;
    00075     data[1] = contrast;
    00076     return i2cMasterSendNI(MAX517_I2C_BASE_ADDR, 2, data);
    00077 }
    00078
    00079 void spyglassLcdWrite(u08 rs, u08 data)
    00080 {
    00081     // prepare LCD control lines
    00082     PcfCtrlData &= ~(SPYGLASS_LCD_RW | SPYGLASS_LCD_RS | SPYGLASS_LCD_E);
    00083     if(rs)
    00084         PcfCtrlData |= SPYGLASS_LCD_RS;
    00085     // set LCD control lines
    00086     pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
    00087     // set data lines
    00088     pcf8574Write(PCF_NODE_LCD_DATA, data);
    00089     // clock E line
    00090     pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData|SPYGLASS_LCD_E);
    00091     pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
    00092 }
    00093
    00094 void spyglassLcdWriteChar(u08 c)
    00095 {
    00096     spyglassLcdWrite(1,c);
    00097 }
    00098
    00099 void spyglassLcdInit(void)
    00100 {
    00101     // LCD function set
    00102     spyglassLcdWrite(0,LCD_FUNCTION_DEFAULT);
    00103     // clear LCD
    00104     spyglassLcdWrite(0,1<<LCD_CLR);
    00105     delay(60000);   // wait 60ms
    00106     // set entry mode
    00107     spyglassLcdWrite(0,1<<LCD_ENTRY_MODE | 1<<LCD_ENTRY_INC);
    00108     // set display to on
    00109     spyglassLcdWrite(0,1<<LCD_ON_CTRL | 1<<LCD_ON_DISPLAY );
    00110     // move cursor to home
    00111     spyglassLcdWrite(0,1<<LCD_HOME);
    00112     // set data address to 0
    00113     spyglassLcdWrite(0,1<<LCD_DDRAM | 0x00);
    00114
    00115     // set contrast
    00116     spyglassSetLcdContrast(20);
    00117 }
    00118
    00119 void spyglassLcdHome(void)
    00120 {
    00121     // move cursor to home
    00122     spyglassLcdWrite(0,1<<LCD_HOME);
    00123 }
    00124
    00125 void spyglassLcdClear(void)
    00126 {
    00127     // clear LCD
    00128     spyglassLcdWrite(0,1<<LCD_CLR);
    00129 }
    00130
    00131 void spyglassLcdGotoXY(u08 x, u08 y)
    00132 {
    00133     register u08 DDRAMAddr;
    00134
    00135     // remap lines into proper order
    00136     switch(y)
    00137     {
    00138     case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
    00139     case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
    00140     case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
    00141     case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
    00142     default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
    00143     }
    00144
    00145     // set data address
    00146     spyglassLcdWrite(0,1<<LCD_DDRAM | DDRAMAddr);
    00147 }