//Displaying "HELLO" on LCD for Axiom Peripheral board on TWR-HCS12G128 Tower module //Modified and tested by Mazidi from chapter 12 //From Example 12-2C of HCS12 Microcontroller and Embedded System by Mazidi/Causey //Thanks to Shu-Jen Chen for his input. //The Axiom Peripheral Board (TWR-DEV-PERIPH) comes with an on-board LCD. //The LCD used is EADOGM163E from http://www.soselectronic.com/a_info/resource/d/ea/dog-m.pdf //EADOGM163E LCD uses ST7036 controller instead of the older one which was based on HD44780 controller //This LCD has 3 lines of 16-characters. //It uses addresses 00 to 0x0F for the 16 characters //The address positions are 0x00-0x0F for line 1 (the same as the older HD44780-based LCD), //0x10-0x1F for line 2 and 0x20-0x2F for line 3. Notice line 2 and 3 are different from the HD44780-based LCDs //So we add the above hex poistion to value ox80. Therefore, we have 0x80-0x8F for line 1, //0x90-0x9F for line 2 and 0xA0-0xAF for line 3 //For basic text, the ST7036 is compatibe with HD44780-based LCDs //The ST7036 has a new pin CSB (Chip select) which HD44780-LCD did not have. The CSB is active Low. //It has many powerful and complex features. //For ST7036 datasheet, see http://www.lcd-module.de/eng/pdf/zubehoer/st7036.pdf //HCS12 PORTC is connected to LCD pins in the Axiom Peripheral board. //D7-D4 ----> PORTC7-PORTC4 (4-bit option) //RS---------> PORTCo //En ---------> PORTC2 //the RW is grounded so we can only write to LCD //CSB pin of LCD is active low and is connected to PORTB_7 pin of HCS12 via JP5 by Axiom //PORTP0 controls the Backlight and can be programmed using PWM. //See Axiom website for TWR-DEV-PERIPH user guide/schematic http://www.axman.com/content/twr-dev-periph-0 //On the Axiom TWR-DEV-PERIPH board make sure you have jumpers: JP1 set on the left, JP2 is set, and JP3,JP4, and JP5 on the right. //Use F7 to Make, F5 (Debug) to download, and F5 (Start) to run the program //In CodeWarrior,make sure you are in Open Source BDM when downloading and running. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ #define LCD_DATA PORTC #define LCD_CTRL PORTC #define RS 0x01 // PORTCo for RS pin of LCD #define EN 0x04 // PORTC2 for en pin of LCd void COMWRT4(unsigned char); void DATWRT4(unsigned char); void MSDelay(unsigned int); void main(void) { DDRC = 0xFF; //PORTC=output for data and control signals DDRB = DDRB | 0x80; //PB7 as output PORTB = PORTB & 0x7F; //PB7=0 for CSB pin of LCD DDRP = DDRP | 1; //PORTP7 as output for backlight control PTP = PTP | 1; //turn on the backlight (optional) PORTC =0x0; MSDelay(10); //Many of the initialization commmands of ST7036 LCD is the same as HD44780 covered in the Mazidi/Causey textbook. //However, for ST7034-bases LCD we need few more commands. See Page 42 of ST7036 datasheet COMWRT4(0x33); MSDelay(1); COMWRT4(0x32); MSDelay(1); COMWRT4(0x29); //Function set:DL=0(4-bit) This option is compatibe with HD44780-LCD MSDelay(1); //These are new and extra commands unique to ST7036-based LCD. See page 42 of ST7036 datasheet COMWRT4(0x15); //Bias MSDelay(1); COMWRT4(0x78); //Contrast MSDelay(1); COMWRT4(0x5E); //Power/ICON/Contrast MSDelay(1); COMWRT4(0x6A); //Follower Control MSDelay(1); //These comands are the same COMWRT4(0x0E); //Display on and Cursor on MSDelay(1); COMWRT4(0x01); //Clear LCD MSDelay(1); COMWRT4(0x06); //shift cursor right for Entry Mode MSDelay(1); COMWRT4(0x85); //cursor position. Use 0x80-0x8F for line 1, MSDelay(1); //0x90-0x9F for line 2 and 0xA0-0xAF for line 3 //sending ASCII characters to be displayed DATWRT4('H'); MSDelay(1); DATWRT4('E'); MSDelay(1); DATWRT4('L'); MSDelay(1); DATWRT4('L'); MSDelay(1); DATWRT4('O'); for(;;); //stay here } void COMWRT4(unsigned char command) { unsigned char x; x = command & 0xF0; //mask the low nibble LCD_DATA = LCD_DATA & 0x0F; //clear PC7-PC4 pins before you send it anything LCD_DATA = LCD_DATA | x; //sends high nibble to PORTC MSDelay(1); LCD_CTRL = LCD_CTRL & ~RS; //set RS to command (RS=0) MSDelay(1); LCD_CTRL = LCD_CTRL | EN; //raise enable MSDelay(5); LCD_CTRL = LCD_CTRL & ~EN; //Drop enable to capture command MSDelay(15); //wait x = command & 0x0F; // mask high nibble x= x<<4; //shift it to upper nibble LCD_DATA = LCD_DATA & 0x0F; //clear PC7-PC4 pins before you send it anything LCD_DATA =LCD_DATA | x; //send low nibble to PORTC LCD_CTRL = LCD_CTRL | EN; //raise enable MSDelay(5); LCD_CTRL = LCD_CTRL & ~EN; //drop enable to capture command MSDelay(15); } void DATWRT4(unsigned char data) { unsigned char x; x = (data & 0xF0); LCD_DATA = LCD_DATA & 0x0F; //clear PC7-PC4 pins before you send it anything LCD_DATA = LCD_DATA | x; MSDelay(1); LCD_CTRL = LCD_CTRL | RS; MSDelay(1); LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(15); x = (data & 0x0F); x= x<<4; LCD_DATA = LCD_DATA & 0x0F; //clear PC7-PC4 pins before you send it anything LCD_DATA = LCD_DATA | x; LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(15); } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i