////////////////////////////////////////////////////////////////////////////////// // // 文件名 :LCDscreen.c // // ///////////////////////////////////////////////////////////////////////////////// #include "LCDscreen.h" void LCDBusy_Check(uint8 Channel) ; ///////////////////////////////////////////////////////////////////////////// // 列:对应LCM的page ,行 // uint8 LCMdisplaymemery[8][128] ;//LCM显示数据page:8 ; 列: 128 ///////////////////////////////////////////////////////////////////// // KSO108B base function // /******************************************************************** name : LCDscreen_Init function : P2.18:BLED输出高电平;P2.17:E 设置为输出 parameter: 无 *********************************************************************/ void LCDscreen_Init() { BCFG2 &= 0x0300FBFF ; IO2DIR |= 0x00060000 ; //P2.17 P2.18 : OUT IO2SET |= 0x00040000 ; //P2.18 = 1 } /******************************************************************** name : LCM_WREnable function : LCM读写信号控制 E高电平 parameter: 无 *********************************************************************/ void LCM_WREnable() { IO2SET = 0x00020000 ; //P2.17 = 1 } /******************************************************************** name : LCM_WRDisable function : LCM读写信号控制 E低电平 parameter: 无 *********************************************************************/ void LCM_WRDisable() { IO2CLR = 0x00020000 ; //P2.17 = 0 } /******************************************************************** name : W_LcmInstruct function : 向LCM写指令 parameter: channel : LCM RAM 选择 instruct : 写入LCM的指令 *********************************************************************/ void W_LcmInstruct(uint8 channel,uint8 instruct) { LCDBusy_Check( channel ) ; if( channel == 1 ) { LCDSCREENWIADDR1 = instruct ; } if( channel==2 ) { LCDSCREENWIADDR2 = instruct ; } LCM_WREnable() ; LCM_WRDisable() ; } /******************************************************************** name : W_LcmData function : 向LCM写数据 parameter: channel : LCM RAM 选择 data : 写入LCM的数据 *********************************************************************/ void W_LcmData(uint8 channel,uint8 data) { LCDBusy_Check( channel ) ; if( channel == 1 ) { LCDSCREENWDADDR1 = data ; } if( channel == 2 ) { LCDSCREENWDADDR2 = data ; } LCM_WREnable() ; LCM_WRDisable() ; } /******************************************************************** name : R_LcmInstruct function : 读LCM指令 parameter: channel : LCM RAM 选择 *********************************************************************/ uint8 R_LcmInstruct(uint8 channel) { uint8 temp ; LCDBusy_Check( channel ) ; LCM_WREnable() ; if( channel == 1 ) { temp = LCDSCREENRIADDR1 ;//return (LCDSCREENRIADDR1) ; } if( channel == 2 ) { temp = LCDSCREENRIADDR2 ;//return (LCDSCREENRIADDR2) ; } LCM_WRDisable() ; return temp ; } /******************************************************************** name : R_LcmData function : 读LCM数据 parameter: channel : LCM RAM 选择 *********************************************************************/ uint8 R_LcmData(uint8 channel) { uint8 temp ; LCDBusy_Check( channel ) ; LCM_WREnable() ; if( channel == 1 ) { temp = LCDSCREENRDADDR1 ;//return (LCDSCREENRDADDR1) ; } if( channel == 2 ) { temp = LCDSCREENRDADDR2 ;//return (LCDSCREENRDADDR2) ; } LCM_WRDisable() ; return temp ; } ///////////////////////////////////////////////////////////////////// // KSO108B instruct // /******************************************************************** name : LCDBusy_Check function : LCM状态检测 parameter: Channel : LCM RAM 选择 *********************************************************************/ void LCDBusy_Check(uint8 Channel) { uint8 LCDStatus = 0x80 ; if( Channel == 1 ) { while( ( LCDStatus & 0x80 ) != 0 ) { LCM_WREnable() ; LCDStatus = LCDSCREENRIADDR1 ; //读取LCD1状态。 LCM_WRDisable() ; } } if( Channel == 2 ) { while( ( LCDStatus & 0x80 ) !=0 ) { LCM_WREnable() ; LCDStatus = LCDSCREENRIADDR2; //读取LCD2状态 LCM_WRDisable() ; } } } /******************************************************************** name : Lcm_On function : 显示开/关 指令; parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) anoroff 1:显示RAM中的内容;0 时关闭显示。 *********************************************************************/ void Lcm_OnOff(uint8 channel,uint8 onoroff) { W_LcmInstruct( channel , (0x3e | onoroff) ); } /******************************************************************** name : Lcm_StartRowShow function : 显示起始行ROW 设置指令,该指令设置了对应液晶屏最上一行的 显示RAM 的行号 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) row : 起始行ROW *********************************************************************/ void Lcm_StartRowShow(uint8 channel ,uint8 row) { W_LcmInstruct( channel,(0xc0 | row) ); } /******************************************************************** name : Lcm_SelectPage function : 页PAGE 设置指令,显示 RAM共64 行,分8 页,每页8 行 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) page :页 *********************************************************************/ void Lcm_SelectPage(uint8 channel,uint8 page) { W_LcmInstruct( channel , (0xb8|page) ) ; } /******************************************************************** name : Lcm_SelectY function : 列地址Y Address 设置 指令 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) yaddr : 列地址 *********************************************************************/ void Lcm_SelectY(uint8 channel,uint8 yaddr) { W_LcmInstruct(channel,(0x40|yaddr)) ; } /******************************************************************** name : Lcm_RStat function : 读状态 指令 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) 返回:液晶显示模块内部控制器的状态 *********************************************************************/ uint8 Lcm_RStat(uint8 channel) { return ( R_LcmInstruct(channel) ) ; } /******************************************************************** name : Lcm_WData function : 写数据 指令 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) data :写入LCM的数据 *********************************************************************/ void Lcm_WData(uint8 channel,uint8 data) { W_LcmData(channel,data) ; } /******************************************************************** name : Lcm_RData function : 读数据 指令 parameter: channel 1:选择KSO108B(1);2: 选择KSO108B(2) *********************************************************************/ uint8 Lcm_RData(uint8 channel) { return ( R_LcmData(channel) ) ; } ///////////////////////////////////////////////////////////////////// // LCM显示实现 // /******************************************************************** name : Lcm_Display function : 显示LCM缓冲区数据 parameter: 无 *********************************************************************/ void Lcm_Display() { uint8 pagescan ; uint8 Yscan ; for( pagescan = 0 ; pagescan < 0x08 ; pagescan ++ ) { for( Yscan = 0 ; Yscan <64 ; Yscan ++ ) { Lcm_SelectPage( 2 , 7 - pagescan ) ; Lcm_SelectY( 2 , 63 - Yscan ) ; Lcm_WData( 2 , LCMdisplaymemery[pagescan][Yscan] ) ; } } for( pagescan = 0 ; pagescan < 0x08 ; pagescan ++ ) { for( Yscan = 0 ; Yscan <64 ; Yscan ++ ) { Lcm_SelectPage( 1 , 7 - pagescan ) ; Lcm_SelectY( 1 , 63 - Yscan ) ; Lcm_WData( 1 , LCMdisplaymemery[pagescan][Yscan+64] ) ; } } Lcm_StartRowShow( 1 , 0 ) ; Lcm_OnOff( 1 , 1 ); Lcm_StartRowShow( 2 , 0 ) ; Lcm_OnOff( 2 , 1 ) ; } ///////////////////////////////////////////////////////////////////////////// // API interface function ///////////////////////////////////////////////////////////////////////////// // (0,0) // o------------------>y // | // | // | // | // | // | // V // x /**************************************************************************** name : WLCMDisplayMemery_Char function : 向显示缓冲区指定位置写字符 parameter: x : 显示缓冲区指定位置起始纵坐标 y : 显示缓冲区指定位置起始横坐标 str:要写入显示缓冲区的字符 *****************************************************************************/ void WLCMDisplayMemery_Char( uint8 x , uint8 y , char str ) { uint8 temp_page ; uint8 temp_data ; uint8 temp_count ; temp_page = ( x/8 ) ; //起始页 if( (x % 8) == 0 ) //同页 { for( temp_count = 0 ; temp_count < 8 ; temp_count ++ ) { LCMdisplaymemery[temp_page][y+temp_count] = charactercode[str-33][temp_count] ; } } else //不同页 { for( temp_count =0 ; temp_count < 8 ; temp_count ++ ) { temp_data = ( charactercode[str][temp_count] >> ( x % 8 ) ) ;/////////////////str-33 LCMdisplaymemery[temp_page][y+temp_count] = temp_data ; } for( temp_count =0 ; temp_count < 8 ; temp_count ++ ) { temp_data = ( charactercode[str][temp_count] << ( 8-( x % 8 ) ) ) ;/////////////////str-3 LCMdisplaymemery[temp_page+1][y+temp_count] = temp_data ; } } } /***************************************************************************** name : LCMCharOut function : LCM单个字符显示 parameter: x : 字符显示起始纵坐标 y : 字符显示起始横坐标 str:要显示的字符 *****************************************************************************/ void LCMCharOut( uint8 x , uint8 y , char str ) { WLCMDisplayMemery_Char( x , y , str ) ; //显示LCM缓冲区数据 Lcm_Display() ; } /***************************************************************************** name : LCMStringOut function : LCM字符串显示 parameter: x : 字符串显示起始纵坐标 y : 字符串显示起始横坐标 str:要显示的字符串 ******************************************************************************/ void LCMStringOut( uint8 x , uint8 y , char string[] ) { uint8 temp_count ; for( temp_count = 0 ;temp_count < 128 ; temp_count ++ ) { if( string[temp_count] != '\0' ) { WLCMDisplayMemery_Char( x , y + temp_count*8 , string[temp_count] ) ; } if( string[temp_count] == '\0' ) { break ; } } //显示LCM缓冲区数据 Lcm_Display() ; } ////////////////////////////////////////////////////////////////////////////////// // // 文件名 :LCDscreen.h // // ///////////////////////////////////////////////////////////////////////////////// #ifndef _LCDSCREEN_H #define _LCDSCREEN_H #include "config.h" #include "character.h" //////////////////////////debug/////////////////////////////////////// // #include "sound.h" extern uint8 LCMdisplaymemery[8][128] ;//LCM显示数据page:8 ; 列: 128 #define LCDSCREENRAM1ADDR 0x82080000 //0x82080000 #define LCDSCREENRAM2ADDR 0x820c0000 //0x820c0000 #define WINSTRUCT 0x00000000 #define WDATA 0x00000001 #define RINSTRUCT 0x00000002 #define RDATA 0x00000003 #define LCDSCREENWIADDR1 (*((volatile unsigned char *)(LCDSCREENRAM1ADDR+WINSTRUCT))) #define LCDSCREENWDADDR1 (*((volatile unsigned char *)(LCDSCREENRAM1ADDR+WDATA))) #define LCDSCREENRIADDR1 (*((volatile unsigned char *)(LCDSCREENRAM1ADDR+RINSTRUCT))) #define LCDSCREENRDADDR1 (*((volatile unsigned char *)(LCDSCREENRAM1ADDR+RDATA))) #define LCDSCREENWIADDR2 (*((volatile unsigned char *)(LCDSCREENRAM2ADDR+WINSTRUCT))) #define LCDSCREENWDADDR2 (*((volatile unsigned char *)(LCDSCREENRAM2ADDR+WDATA))) #define LCDSCREENRIADDR2 (*((volatile unsigned char *)(LCDSCREENRAM2ADDR+RINSTRUCT))) #define LCDSCREENRDADDR2 (*((volatile unsigned char *)(LCDSCREENRAM2ADDR+RDATA))) void Lcm_Display(void) ; void LCDscreen_Init(void) ; void LCMCharOut( uint8 x , uint8 y , char str ) ; void LCMStringOut( uint8 x , uint8 y , char string[] ) ; #endif ////////////////////////////////////////////////////////////////////////////////// // // 文件名 :LCD_SDisplay.c // // ///////////////////////////////////////////////////////////////////////////////// #include "LCDscreen.h" /********************************************************************** name : function : parameter: ***********************************************************************/ int main() { soundinit() ; LCDscreen_Init() ; LCMCharOut( 56,3,'1') ; LCMStringOut(1,0,"this is c !") ; while(1) ; return 0 ; } ////////////////////////////////////////////////////////////////////////////////// // // 文件名 :Character.c // // ///////////////////////////////////////////////////////////////////////////////// #include "character.h" uint8 a[8] = {0x11,0x3A,0x54,0x9A,0x55,0x44,0x5F,0x64}; uint8 b[8] ={0x00,0x03,0x81,0x81,0xFF,0x80,0x80,0x00}; uint8 charactercode[][8]={ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, ////////////////////////////////////////ASCⅡ 33 ~ 47 {0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00},//! {0x00,0x00,0x06,0x00,0x06,0x00,0x00,0x00},// {0x28,0x28,0xFE,0x28,0xFE,0x28,0x28,0x00},// {0x00,0x4C,0x52,0x52,0xFF,0x52,0x72,0x00},// {0x00,0x40,0x24,0x10,0x08,0x44,0x02,0x00},// {0xC0,0xA0,0x56,0x49,0x35,0x62,0x98,0x80},// {0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x00},// {0x00,0x00,0x3C,0x42,0x81,0x00,0x00,0x00},// {0x00,0x00,0x00,0x81,0x42,0x3C,0x00,0x00},// {0x92,0x54,0x38,0xFE,0x38,0x54,0x92,0x00},// {0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x00},//+ {0x00,0x08,0x04,0x02,0x00,0x00,0x00,0x00},// {0x00,0x00,0x00,0x20,0x20,0x00,0x00,0x00},//, {0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},// {0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x00},//。 ////////////////////数字////////////////////ASCⅡ 48 ~ 57 {0x00,0x3E,0x41,0x41,0x41,0x41,0x3E,0x00},//0 {0x00,0xC1,0x81,0xFF,0xFF,0x01,0x01,0x00},//1 {0x00,0xDE,0x92,0x92,0x92,0x92,0xF6,0x00},//2 {0x00,0x63,0x49,0x49,0x49,0x49,0x7F,0x00},//3 {0x00,0xF8,0x08,0x08,0xFF,0x08,0x08,0x00},//4 {0x00,0xF3,0x91,0x91,0x91,0x91,0x9F,0x00},//5 {0x00,0xFF,0x89,0x89,0x89,0x89,0xCF,0x00},//6 {0x00,0x00,0xC0,0x81,0x8F,0x91,0xE0,0x00},//7 {0x00,0x00,0x7E,0x89,0x89,0x89,0x7E,0x00},//8 {0x00,0x00,0xF3,0x91,0x91,0x91,0xFF,0x00},//9 ///////////////////////符号/////////////////ASCⅡ 58 ~ 64 {0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00}, {0x00,0x00,0x00,0x4D,0x2D,0x1D,0x00,0x00},//; {0x00,0x10,0x28,0x44,0x82,0x00,0x00,0x00}, {0x00,0x28,0x28,0x28,0x28,0x28,0x28,0x00}, {0x00,0x82,0x44,0x28,0x10,0x00,0x00,0x00}, {0x00,0x00,0x0E,0x02,0xB2,0x12,0x1E,0x00}, {0x7E,0x81,0x99,0xA5,0xA5,0xB9,0xA1,0xDE},//@ ////////////////26个大写英文字母//////////////ASCⅡ 65 ~ 90 {0xC0,0x30,0x2C,0x23,0x23,0x2C,0x30,0xC0}, {0x00,0xFF,0x89,0x89,0x89,0x7E,0x00,0x00}, {0x00,0x00,0xFF,0x81,0x81,0x81,0xC3,0x00}, {0x00,0xFF,0x81,0x81,0x81,0x81,0x7E,0x00}, {0x00,0xFF,0x89,0x89,0x89,0x89,0x89,0x00}, {0x00,0xFF,0x11,0x11,0x11,0x11,0x00,0x00}, {0x00,0x7E,0x81,0x81,0x81,0xA1,0xE0,0x00}, {0x81,0xFF,0x91,0x10,0x10,0x91,0xFF,0x81}, {0x00,0x00,0x81,0xFF,0x81,0x00,0x00,0x00}, {0x00,0xC0,0x81,0x81,0xFF,0x01,0x00,0x00}, {0x00,0x81,0xFF,0x91,0x28,0x44,0x82,0x00}, {0x00,0x00,0xFF,0x80,0x80,0x80,0x80,0x00}, {0xFE,0x02,0x02,0xFE,0x02,0x02,0xFE,0x00}, {0x00,0xFF,0x03,0x04,0x08,0x10,0xC0,0xFF}, {0x00,0x7E,0x81,0x81,0x81,0x81,0x7E,0x00}, {0x00,0x00,0xFF,0x09,0x09,0x09,0x06,0x00}, {0x7E,0x81,0x81,0xA1,0xE1,0xFF,0x80,0x80}, {0x00,0xFF,0x19,0x29,0x49,0x8E,0x80,0x00}, {0x00,0x8E,0x91,0x91,0x91,0xE1,0x00,0x00}, {0x00,0x01,0x01,0xFF,0x01,0x01,0x00,0x00}, {0x02,0x7E,0x82,0x80,0x80,0x82,0x7E,0x02}, {0x1E,0x20,0x40,0x80,0x80,0x40,0x20,0x0E}, {0xFE,0x80,0x80,0xFE,0x80,0x80,0xFE,0x00}, {0x81,0xC3,0x24,0x18,0x18,0x24,0xC3,0x81}, {0x01,0x03,0x04,0xF8,0x04,0x03,0x01,0x00}, {0x80,0xC1,0xA1,0x91,0x89,0x85,0x83,0x00}, //////////////////////////////////////////////ASCⅡ 91 ~ 96 {0x00,0x00,0xFF,0x81,0x00,0x00,0x00,0x00}, {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, {0x00,0x00,0x00,0x81,0xFF,0x00,0x00,0x00}, {0x10,0x08,0x04,0x02,0x02,0x04,0x08,0x10}, {0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00}, {0x00,0x00,0x00,0x00,0x10,0x20,0x40,0x00}, ////////////////小写字母//////////////////////ASCⅡ 97 ~ 122 {0x00,0x3E,0x41,0x41,0x41,0x3F,0x01,0x00}, {0x00,0xFF,0x09,0x09,0x09,0x0F,0x00,0x00}, {0x00,0x1C,0x22,0x41,0x41,0x41,0x01,0x00},//c {0x00,0x0E,0x11,0x11,0x11,0x11,0xFF,0x00}, {0x00,0x3E,0x49,0x49,0x49,0x49,0x31,0x00},//e {0x00,0x01,0x7E,0x90,0x90,0x90,0x00,0x00},//f {0x00,0x00,0x72,0x89,0x89,0x89,0x7E,0x00},//g {0x00,0x00,0xFF,0x10,0x10,0x0F,0x00,0x00},//h {0x00,0x00,0x21,0xBF,0x01,0x00,0x00,0x00},//i {0x00,0x00,0x02,0x21,0xBF,0x00,0x00,0x00},//j {0x00,0x00,0xFF,0x08,0x14,0x22,0x41,0x00},//k {0x00,0x00,0xFF,0x01,0x01,0x03,0x00,0x00},//l {0x3F,0x40,0x40,0x7F,0x40,0x40,0x3F,0x00},//m {0x00,0x3F,0x40,0x40,0x40,0x40,0x3F,0x00},//n {0x1C,0x22,0x41,0x41,0x41,0x41,0x22,0x1C},//o {0x00,0x01,0xFF,0x90,0x90,0x90,0x60,0x00},//p {0x00,0x60,0x90,0x90,0x90,0xFF,0x01,0x00},//q {0x00,0x80,0x40,0x3F,0x40,0x80,0x80,0x00},//r {0x00,0x00,0x66,0x91,0x91,0x91,0x4E,0x00},//s {0x10,0x10,0x10,0xFE,0x11,0x11,0x11,0x02},//t {0x00,0x00,0x3E,0x01,0x01,0x01,0x3F,0x01},//u {0x70,0x08,0x04,0x02,0x04,0x08,0x70,0x00},//v {0x7C,0x02,0x02,0x7E,0x02,0x02,0x7C,0x00},//w {0x00,0x21,0x12,0x08,0x04,0x12,0x21,0x00},//x {0x00,0xF2,0x11,0x11,0x11,0xFE,0x00,0x00},//y {0x00,0x41,0x43,0x45,0x49,0x51,0x63,0x00},//z /*************************************************/ {0x00,0x00,0x10,0xEF,0x81,0x81,0x00,0x00}, {0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00}, {0x00,0x00,0x81,0xEF,0x10,0x00,0x00,0x00}, {0x40,0x20,0x10,0x10,0x10,0x10,0x08,0x04}, }; ////////////////////////////////////////////////////////////////////////////////// // // 文件名 :Character.h // // ///////////////////////////////////////////////////////////////////////////////// #ifndef _CHARACTER_H #define _CHARACTER_H #include "config.h" extern uint8 a[8] ; extern uint8 b[8] ; extern uint8 charactercode[][8] ; #endif
文章评论(0条评论)
登录后参与讨论