1 | /*************************************************************************************************************
|
2 | SG12232A_Demo.c
|
3 |
|
4 | This is a demonstration of the SG12232A and graphics driver running on a PIC16F877A
|
5 |
|
6 | Version 1.0 Apr 2009
|
7 |
|
8 | Copyright 2009 Geoff Graham - http://geoffg.net
|
9 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
|
10 | Public License as published by the Free Software Foundation, either version 2 of the License, or (at your
|
11 | option) any later version.
|
12 |
|
13 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
14 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15 | for more details. You should have received a copy of the GNU General Public License along with this program.
|
16 | If not, see <http://www.gnu.org/licenses/>.
|
17 |
|
18 | Development Environment
|
19 | To compile this you need:
|
20 | - CCS C Compiler Version 4.0 or higher (www.ccsinfo.com)
|
21 | - Microchip MPLAB IDE Version 8.0 or higher (www.microchip.com)
|
22 |
|
23 | Caveats:
|
24 | - It is written for the CCS C compiler
|
25 | - The 16F877A uses an approx 8MHz clock consisting of a 2.2K resistor and 27pF cap on OSC1 (pin 13)
|
26 | - The 4KHz clock for the LCD is generated by a never ending loop (not practical in the real world)
|
27 |
|
28 | Overworked:
|
29 | - It is written for the CCS C Compiler
|
30 | - The 18F4550 uses an external Oscilator with 20 MHz (HS).
|
31 | - A 2 KHz clock for the Vee on the LCD is generatd by an NE555 on the LCD Platine
|
32 | - TrisX and PortX Special Function Registers (SFR) settings are changed.
|
33 |
|
34 | ***************************************************************************************************************/
|
35 |
|
36 | #include <18f4550.h>
|
37 | #device ADC=8 // read just 8 bits from the ADC
|
38 | #fuses HSPLL,CPUDIV1,USBDIV,VREGEN,NOPBADEN,WRTB,NOWDT,NOPUT,NOCPD,NOWRT,NOPROTECT,NOBROWNOUT,NOLVP,DEBUG,PLL5,MCLR
|
39 |
|
40 | // Clock Related Fuses (select one):
|
41 | // LP – Low-Power Crystal
|
42 | // XT – Crystal/Resonator
|
43 | // HS – High-Speed Crystal/Resonator
|
44 | // RC – External Resistor-Capacitor (RC) with FOSC/4 output on RA6
|
45 | // Watch Dog Timer: WDT, NOWDT
|
46 | // Power-up Timer: PUT,NOPUT
|
47 | // Protect Code: PROTECT,NOPROTECT
|
48 | // In-Circuit Debugger Mode: DEBUG,NODEBUG
|
49 | // Brown-out Detect: BROWNOUT,NOBROWNOUT
|
50 | // Low-Volt Programming Enable: LVP, NOLVP
|
51 | // Protect Data Memory: CPD,NOCPD
|
52 | // Prog mem write protected WRT_50%,WRT_5%,WRT_25%,NOWRT
|
53 |
|
54 | /*************************************************************
|
55 | ******* Map reset vector and interrupt vector *******
|
56 | ******* 0x000-0x7FF is used by the bootloader. The *******
|
57 | ******* Bootloader maps the original reset vector (0x000) ***
|
58 | ******* to 0x800 andthe interrupt vector (0x008) to 0x808 ***
|
59 | *************************************************************/
|
60 |
|
61 | #build (reset=0x800, interrupt=0x808)
|
62 |
|
63 | /*************************************************************
|
64 | ******* Reserve boot block area *******
|
65 | ******* This memory range is used by the bootloader, *******
|
66 | ******* so the application could not use this area too ******
|
67 | ************************************************************/
|
68 |
|
69 | #org 0, 0x7FF {}
|
70 |
|
71 | /************************************************************/
|
72 |
|
73 |
|
74 | // processor specific hardware registers - Now for the 18F4550
|
75 | #byte porta = 0xF80 // Port A I/O register
|
76 | #byte portb = 0xF81 // Port A I/O register
|
77 | #byte portd = 0xF83 // Port B I/O register
|
78 | #byte tris_a = 0xF92 // Port A TRIS register
|
79 | #byte tris_b = 0xF93 // Port B TRIS register
|
80 | #byte tris_d = 0xF95 // Port B TRIS register
|
81 |
|
82 | #use delay(clock=48000000)
|
83 |
|
84 | #use fast_io(A)
|
85 | #use fast_io(B)
|
86 | #use fast_io(D)
|
87 |
|
88 | #define TRISA_INIT 0b00000000 // this MUST agree with the #defines below
|
89 | #BIT LCD_CS2 = porta.0 // output LCD Chip Select 1
|
90 | #BIT LCD_CS1 = porta.1 // output LCD Chip Select 2
|
91 | #BIT LCD_A0 = porta.2 // output LCD A0
|
92 | #BIT LCD_RW = porta.4 // output LCD Read/Write
|
93 |
|
94 | #define TRISB_INIT 0b00000000 // this MUST agree with the #defines below
|
95 | //#BIT LCD_CLK = portb.0 // output LCD Clock (approx 4KHz squarewave)
|
96 | #BIT LED_B0 = portb.0
|
97 | #BIT LCD_E = portb.1 // output LCD Enable (data strobe)
|
98 |
|
99 | #BIT D0 = portd.0 // input & output - Data bus to LCD
|
100 | #BIT D1 = portd.1 // input & output - Data bus to LCD
|
101 | #BIT D2 = portd.2 // input & output - Data bus to LCD
|
102 | #BIT D3 = portd.3 // input & output - Data bus to LCD
|
103 | #BIT D4 = portd.4 // input & output - Data bus to LCD
|
104 | #BIT D5 = portd.5 // input & output - Data bus to LCD
|
105 | #BIT D6 = portd.6 // input & output - Data bus to LCD
|
106 | #BIT D7 = portd.7 // input & output - Data bus to LCD
|
107 |
|
108 | #define LCD_DATA portd // Data port for the LCD
|
109 | #define LCD_DATA_TRIS tris_d // and its associated direction register
|
110 |
|
111 |
|
112 | // define some easy to remember types
|
113 | #define bit int1
|
114 | #define int8 signed int8
|
115 | #define uint8 unsigned int8
|
116 | #define int16 signed int16
|
117 | #define uint16 unsigned int16
|
118 | #define int32 signed int32
|
119 | #define uint32 unsigned int32
|
120 |
|
121 | /**********************************************************************************************
|
122 | Main program
|
123 | **********************************************************************************************/
|
124 | #include "./SG12232A_Driver_1_0.h" // this is the LCD driver
|
125 | #include "./glcd_library_1_0.h" // and this is a universal graphics/fonts package
|
126 |
|
127 | void main() {
|
128 | setup_adc_ports(NO_ANALOGS);
|
129 | setup_comparator(NC_NC_NC_NC);
|
130 | SETUP_TIMER_0(RTCC_INTERNAL);
|
131 |
|
132 | // set pin directions
|
133 | tris_a = TRISA_INIT;
|
134 | tris_b = TRISB_INIT;
|
135 |
|
136 | LCD_CS2 = LCD_CS1 = LCD_A0 = 1;
|
137 | LCD_RW = LCD_E = 0;
|
138 |
|
139 | GLCD_Init(); // defined in SG12232A_Driver.h
|
140 | delay_ms(1000); // time for Init GLCD
|
141 | glcd_setxy(0, 0, 1); // defined in glcd_library.h
|
142 | printf(glcd_putc916, "Hello World!"); // glcd_putc916 is defined in glcd_library.h
|
143 | while(1) {
|
144 | //LCD_CLK = !LCD_CLK; // generate an approx 4KHz squarewave for the LCD
|
145 | output_toggle(PIN_B0); // toggles an LED on B0 on and off
|
146 | delay_ms(1000);
|
147 | //delay_us(340); // delay for 1 sec
|
148 | }
|
149 | }
|