1: /***********************************************************************/
2: /* PoE Keypad Test Program */
3: /* */
4: /* Created By: Hussein Nosair */
5: /* Date : 01/27/2009 */
6: /* Project : PoE_kp_testing */
7: /* Proj. Path: C:\codes\PoE_kp_testing */
8: /* File Name : test.c */
9: /* */
10: /* Author Date Comment */
11: /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
12: /* Hussein Nosair 1/14/09 test.c created */
13: /* Hussein Nosair 1/07/09 test.c Fixed configurations bits */
14: /* Hussein Nosair 1/27/09 test.c Fixed bug in main program */
15: /***********************************************************************/
16:
17: /***********************************************************************/
18: /* DEFINE THE MOTHER CODE */
19: /***********************************************************************/
20: #define THIS_IS_STACK_APPLICATION // Define this file to be the main Proj.'s File
21:
22: /***********************************************************************/
23: /* DEFINE THE LIBRARIES */
24: /***********************************************************************/
25: #include "Compiler.h" // Compiler configuration library
26: #include "HardwareProfile.h" // Hardware configuration library
27: #include "GenericTypeDefs.h" // Global definition library
28: #include "LCD.h" // LCD library
29:
30: /***********************************************************************/
31: /* DEFINE STATIC VARIABLES */
32: /***********************************************************************/
33: #define TIMER1_LED_DELAY 2 // LED Timeout = 2*1.67sec
34: #define TMR1_DELAY 5
35:
36: /***********************************************************************/
37: /* DEFINE GLOBAL VARIABLES */
38: /***********************************************************************/
39: unsigned char LEDTime; // Define LED timout
40: unsigned char TMR1Delay;
41:
42: const unsigned char p2[8][8] = {{0,0,0,0,0,0,0,0x1F},
43: {0,0,0,0,0,0,0x1F,0x1F},
44: {0,0,0,0,0,0x1F,0x1F,0x1F},
45: {0,0,0,0,0x1F,0x1F,0x1F,0x1F},
46: {0,0,0,0x1F,0x1F,0x1F,0x1F,0x1F},
47: {0,0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},
48: {0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},
49: {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}};
50:
51: /***********************************************************************/
52: /* DEFINE PRIVATE SUBROUTINES */
53: /***********************************************************************/
54: void InitializeBoard(void); // Define Board's hardware initialization subroutine
55:
56: /***********************************************************************/
57: /* PIC18 Interrupt Service Routines */
58: /***********************************************************************/
59: #pragma interruptlow LowISR
60: void LowISR(void)
61: {
62: if (PIR1bits.TMR1IF)
63: {
64: if(TMR1Delay)
65: {
66: TMR1Delay--;
67: }
68:
69: PIR1bits.TMR1IF = 0;
70: TMR1H = 0x00;
71: TMR1L = 0x00;
72: }
73:
74: }
75:
76: #pragma interruptlow HighISR
77: void HighISR(void){}
78: #pragma code lowVector=0x18
79: void LowVector(void){_asm goto LowISR _endasm}
80: #pragma code highVector=0x8
81: void HighVector(void){_asm goto HighISR _endasm}
82: #pragma code // Return to default code section
83:
84: /***********************************************************************/
85: /* MAIN PROGRAM ROUTINE */
86: /***********************************************************************/
87: void main(void)
88: {
89: unsigned char i;
90: unsigned char j;
91:
92: /************** INITIALIZE THE BOARD ************/
93: InitializeBoard(); // Initialize board and PIC hardware
94:
95: /************** PREPARE THE LCD ****************/
96: LCDErase(); // Clear the LCD
97: LCDHome();
98:
99: /************* LOAD PYRAMID INTO LCD uC ****************/
100: for(i=0; i<8; i++)
101: {
102: LCDCustomChar(i, p2[i]);
103: }
104:
105: i = 0;
106: j = 1;
107: LED_IO = 0;
108: LCD_Move(2,2);
109:
110:
111: /********************** MAIN PROGRAM INFINITE LOOP *******************/
112: while(1) // Loop infinitly
113: {
114: if (!TMR1Delay)
115: {
116: //LED_IO ^= 1;
117:
118: if (i<8)
119: {
120: LCDReadCustomChar(i++);
121: }
122: else if(i<17)
123: {
124: LCDReadCustomChar(16-i);
125: i++;
126: }
127: else
128: {
129: LCDErase();
130: if(j > 4)
131: {
132: j = 1;
133: }
134: LCD_Move(j++,2);
135: i = 0;
136: }
137:
138: TMR1Delay = TMR1_DELAY;
139: }
140: }
141: }
142:
143: /********************************************************************
144: * Function Name: InitializeBoard *
145: * Return Value: None *
146: * Parameters: void *
147: * Description: This routine initialize the on board's *
148: * modules and microprocessor. *
149: ********************************************************************/
150: void InitializeBoard(void)
151: {
152: RCON = 0x80;
153: INTCON = 0xE0;
154: INTCON2 = 0x84;
155: INTCON3 = 0x00;
156:
157: // Digital Pins
158: ADCON1 = 0x0F; // Analog pins to digital
159: CMCON = 0x00; //0xCF;
160: CVRCON = 0x00;
161:
162: // Enable internal PORTB pull-ups
163: INTCON2bits.RBPU = 1;
164:
165: //Enable Interrupts
166: //----------------------
167: RCONbits.IPEN = 1; // Enable interrupt priorities
168: INTCONbits.GIEH = 1;
169: INTCONbits.GIEL = 1;
170:
171: // Timer 1 = 52.428msec
172: //------------------------
173: PIR1bits.TMR1IF = 0;
174: PIE1bits.TMR1IE = 1;
175: IPR1bits.TMR1IP = 0;
176: T1CON = 0xB1;
177: TMR1H = 0x00;
178: TMR1L = 0x00;
179: TMR1Delay = TMR1_DELAY;
180:
181: // Oscillator selection
182: //------------------------
183: OSCTUNE = 0x00; //<-----------
184:
185:
186: //LEDs
187: //------------------------
188: LED_TRIS = 0;
189: LED_IO = 0;
190:
191:
192: // LCD
193: //------------------------
194: LCD_DATA_TRIS = 0x0F; // Set Data Bus Direction to output
195: LCD_RD_WR_TRIS = 0; // Set R/W pin direction to output
196: LCD_RS_TRIS = 0; // Set Reset pin direction to output
197: LCD_E_TRIS = 0; // Set Enable pin direction to output
198: DelayMs(50); // wait for 15ms to allow the voltage to rise to moe than 4.5V
199: ClrWdt();
200:
201:
202: // Initialize LCD
203: LCDInit();
204: }