?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file spyglass.c \brief Spyglass Control Panel UI Board Driver. */
2 //*****************************************************************************
3 //
4 // File Name : 'spyglass.c'
5 // Title : Spyglass Control Panel UI Board Driver
6 // Author : Pascal Stang - Copyright (C) 2005
7 // Created : 7/20/2005
8 // Revised : 7/23/2005
9 // Version : 0.9
10 // Target MCU : Atmel AVR series
11 // Editor Tabs : 4
12 //
13 // This code is distributed under the GNU Public License
14 // which can be found at http://www.gnu.org/licenses/gpl.txt
15 //
16 //*****************************************************************************
17  
18  
19 #include "global.h"
20 #include "rprintf.h"
21 #include "timer.h"
22 #include "i2c.h"
23 #include "spyglass.h"
24  
25 #include "lcd.h"
26  
27 u08 PcfCtrlData;
28  
29 u08 pcf8574Write(u08 nodeAddr, u08 data)
30 {
31 // write data
32 return i2cMasterSendNI(PCF8574_I2C_BASE_ADDR+(nodeAddr<<1), 1, &data);
33 }
34  
35 u08 pcf8574Read(u08 nodeAddr)
36 {
37 u08 data;
38 i2cMasterReceiveNI(PCF8574_I2C_BASE_ADDR+(nodeAddr<<1), 1, &data);
39 return data;
40 }
41  
42 void spyglassInit(void)
43 {
44 i2cInit();
45 i2cSetBitrate(100);
46 PcfCtrlData = (SPYGLASS_LED0 | SPYGLASS_LED1 | SPYGLASS_BEEPER);
47 spyglassSetLeds(0);
48 spyglassSetBeeper(0);
49 }
50  
51 u08 spyglassGetPushbuttons(void)
52 {
53 return ~pcf8574Read(PCF_NODE_BUTTONS);
54 }
55  
56 void spyglassSetLeds(u08 leds)
57 {
58 PcfCtrlData = (PcfCtrlData|0x03) & ~(leds&0x03);
59 pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
60 }
61  
62 void spyglassSetBeeper(u08 state)
63 {
64 if(state)
65 PcfCtrlData &=~SPYGLASS_BEEPER; // beeper on
66 else
67 PcfCtrlData |= SPYGLASS_BEEPER; // beeper off
68 pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
69 }
70  
71 u08 spyglassSetLcdContrast(u08 contrast)
72 {
73 u08 data[2];
74 data[0] = 0;
75 data[1] = contrast;
76 return i2cMasterSendNI(MAX517_I2C_BASE_ADDR, 2, data);
77 }
78  
79 void spyglassLcdWrite(u08 rs, u08 data)
80 {
81 // prepare LCD control lines
82 PcfCtrlData &= ~(SPYGLASS_LCD_RW | SPYGLASS_LCD_RS | SPYGLASS_LCD_E);
83 if(rs)
84 PcfCtrlData |= SPYGLASS_LCD_RS;
85 // set LCD control lines
86 pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
87 // set data lines
88 pcf8574Write(PCF_NODE_LCD_DATA, data);
89 // clock E line
90 pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData|SPYGLASS_LCD_E);
91 pcf8574Write(PCF_NODE_CONTROL, PcfCtrlData);
92 }
93  
94 void spyglassLcdWriteChar(u08 c)
95 {
96 spyglassLcdWrite(1,c);
97 }
98  
99 void spyglassLcdInit(void)
100 {
101 // LCD function set
102 spyglassLcdWrite(0,LCD_FUNCTION_DEFAULT);
103 // clear LCD
104 spyglassLcdWrite(0,1<<LCD_CLR);
105 delay(60000); // wait 60ms
106 // set entry mode
107 spyglassLcdWrite(0,1<<LCD_ENTRY_MODE | 1<<LCD_ENTRY_INC);
108 // set display to on
109 spyglassLcdWrite(0,1<<LCD_ON_CTRL | 1<<LCD_ON_DISPLAY );
110 // move cursor to home
111 spyglassLcdWrite(0,1<<LCD_HOME);
112 // set data address to 0
113 spyglassLcdWrite(0,1<<LCD_DDRAM | 0x00);
114  
115 // set contrast
116 spyglassSetLcdContrast(20);
117 }
118  
119 void spyglassLcdHome(void)
120 {
121 // move cursor to home
122 spyglassLcdWrite(0,1<<LCD_HOME);
123 }
124  
125 void spyglassLcdClear(void)
126 {
127 // clear LCD
128 spyglassLcdWrite(0,1<<LCD_CLR);
129 }
130  
131 void spyglassLcdGotoXY(u08 x, u08 y)
132 {
133 register u08 DDRAMAddr;
134  
135 // remap lines into proper order
136 switch(y)
137 {
138 case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
139 case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
140 case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
141 case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
142 default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
143 }
144  
145 // set data address
146 spyglassLcdWrite(0,1<<LCD_DDRAM | DDRAMAddr);
147 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3