Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14830
  • 博文数量: 14
  • 博客积分: 330
  • 博客等级: 一等列兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-19 19:39
文章分类
文章存档

2011年(14)

我的朋友
最近访客

分类: LINUX

2011-04-21 16:34:17

  我的LCD驱动,列出原码,供探讨改进! #include "Config.h" #include "IO.h" #include "Glob.h" #include "MyClib.h" #include "LCD_Define.h" #include "Logo.h" #include void LCD_CmdWrite(Uchar cmdReg, Uchar cmdData); Uchar LCD_CmdRead(Uchar cmdReg); void LCD_DataWrite(Uchar WrData); void LCD_ChkBusy(void); void LCD_Reset(void); void LCD_Initial(void); void LcdScreenFill(Uchar SetX); void GotoXY(Uchar x1,Uchar y1); void CharOrGrapMode(Uchar CharSet) { vWholChipConVal=(CharSet) ? 0xcd : 0xc5; LCD_CmdWrite(cWholChipConReg,vWholChipConVal); } void ReverAndBold(Uchar RevBold) {//RevBold:bit5bit4:01-R_N_B_Y;10-R_Y_B_N; LCD_CmdWrite(cWholChipCurConReg,0x48|RevBold); } void FontSize(Uchar XSize, Uchar YSize) {//XSize,YSize:00,*1; 01,*2; 02,*3; 03,*4; LCD_CmdWrite(cFonSizConReg,(((XSize&0x03)<<6)|((YSiz e&0x03)<<4))|0x0f); } void ASC_ChiAutoSele(Uchar AscSet) { vFonConVal=(AscSet) ? 0xa4 : 0xa0; LCD_CmdWrite(cFonConReg,vFonConVal); } void SetActiveWindow(Uchar Left, Uchar Right, Uchar Top, Uchar Bottom) { LCD_CmdWrite(cActiWinLeReg, Left); LCD_CmdWrite(cActiWinRiReg, Right); LCD_CmdWrite(cActiWinToReg, Top); LCD_CmdWrite(cActiWinBoReg, Bottom); } void PageOperate(Uchar PaMo, Uchar PaOp, Uchar DisPa) { //PaMo:01,p1; 02,p2; 03,p1+p2; 07,exp(p1+p2); PaOp:0,|; 1,^; 2,~; 3,&; //DisPa:0,p0; 1,p1; 2,p2; 3,p1+p2; vMemAccModVal=0x80+((PaMo&0x07)<<4)+((PaOp&0x03)<<2)+( DisPa&0x03); LCD_CmdWrite(cMemAccModReg, vMemAccModVal); } void LCD_OFF(void) { LCD_CmdWrite(cWholChipConReg, vWholChipConVal&0b11111011); } void LCD_ON(void) { LCD_CmdWrite(cWholChipConReg, vWholChipConVal |0b00000100); } #define _dt 1 void LCD_CmdWrite(Uchar cmdReg, Uchar cmdData) { LCD_ChkBusy(); LCD_WR = 1; LCD_RD = 1; LCD_RS = 0; LCD_DATA = cmdReg; LCD_CS1 = 0; LCD_WR = 0; Delay4Xus(_dt); LCD_WR = 1; LCD_CS1 =1; LCD_RS = 0; LCD_DATA = cmdData; LCD_CS1 =0; LCD_WR = 0; Delay4Xus(_dt); LCD_WR = 1; LCD_RS = 1; LCD_CS1 =1; LCD_DATA=0xff; } Uchar LCD_CmdRead(Uchar cmdReg) { Uchar REG_Read; LCD_ChkBusy(); LCD_DATA = cmdReg; LCD_CS1 =0; LCD_RD = 1; LCD_RS = 0; LCD_WR = 0; Delay4Xus(_dt); LCD_WR = 1; LCD_RS = 1; LCD_CS1 =1; LCD_DATA = 0xff; LcdDataDir = 0XFF; Delay4Xus(_dt); LCD_CS1 = 0; LCD_WR = 1; LCD_RS = 0; LCD_RD = 0; Delay4Xus(_dt); REG_Read = LCD_DATA; LCD_RD = 1; LCD_RS = 1; LCD_CS1 =1; LcdDataDir = 0X00; LcdDataDir = 0XFF; return REG_Read; } void LCD_DataWrite(Uchar WrData) { LCD_ChkBusy(); LCD_WR = 1; LCD_RD = 1; LCD_RS = 1; LCD_DATA = WrData; LCD_CS1 =0; LCD_WR = 0; Delay4Xus(_dt); LCD_WR = 1; LCD_CS1 =1; LCD_RS = 1; LCD_DATA=0xff; } void LCD_ChkBusy(void) { #if 0 do { TrisBusy=1; Delay4Xus(20); } while(LCD_BUSY==1); #else Delay4Xus(5); #endif } void LCD_Reset(void) { LCD_DATA = 0XFF; LCD_RST = 1; LCD_CS1 =1; LCD_RD = 1; LCD_RS = 1; LCD_WR = 1; Delay4Xus(_dt); LCD_RST = 0; DelayMs(20); LCD_RST = 1; DelayMs(100); } void LcdScreenFill(Uchar SetX) { Uchar READ_REG; Uchar i,j; LCD_CmdWrite(cPattDatReg,SetX); // READ_REG = LCD_CmdRead(0xF0); // READ_REG &= 0xF7; // READ_REG |= 0x08; READ_REG=0xA8; LCD_CmdWrite(cFonConReg,READ_REG); DelayMs(1); LCD_DataWrite(SetX); } void GotoXY(Uchar x1,Uchar y1) { LCD_CmdWrite(cCursorPosXReg,x1); // 设定水平坐标地址 LCD_CmdWrite(cCursorPosYReg,y1); // 设定垂直坐标地址 } void LCD_Initial(void) { LCD_CmdWrite(cWholChipConReg,0x20); // LCD 基本显示功能设定-1 DelayMs(5); LCD_CmdWrite(cWholChipConReg,0xcd); LCD_CmdWrite(cWholChipCurConReg,0x6b); // LCD 基本显示功能设定-2 LCD_CmdWrite(cDistOfWordOrLineReg,0x10); // 设定光标高度与行距 LCD_CmdWrite(cShifClkConReg,0x04); LCD_CmdWrite(cFonConReg,0xa0); // 设定中文字型为"BIG5" LCD_CmdWrite(cClkBusyFreqReg,0xf2); // 系统工作频率与中断准位设定 SetActiveWindow(0, 39, 0, 239); LCD_CmdWrite(cDisWinBoReg,0xEF); // 设定LCD 模块水平起始地址(Y1) LCD_CmdWrite(cDisWinLeReg,0x00); // 设定LCD 模块垂直结束地址(X2) LCD_CmdWrite(cDisWinToReg,0x00); // 设定LCD 模块水平结束地址(Y2) LCD_CmdWrite(cFraRatComAReg,0x40); // 变换FRM 极性的起始地址(Common) LCD_CmdWrite(cContraConReg,0x20); // 设定DAC 电流输出,可调整LCD 亮度 LCD_CmdWrite(cAdvPowSetReg,0x30); // LCD 内存读写速度与功能设定 LCD_CmdWrite(cAdvDisSetReg,0x80); // LCD 特殊显示功能 LCD_CmdWrite(cMemAccModReg,0x91); // LCD 显示图层设定 vMemAccModVal=0x91; GotoXY(0, 0); LCD_CmdWrite(cBegSegmPosReg,0x00); // 设定垂直开始显示地址(Segment) LCD_CmdWrite(cBegCommReg,0x00); // 设定于水平区块移动模式下,起始地址 LCD_CmdWrite(cEndCommReg,0xEF); // 设定于水平区块移动模式下,结束地址 LCD_CmdWrite(cBlinkTimReg,0x33); // 光标闪烁时间设定 LCD_CmdWrite(cFraRatComBReg,0x00); // 变换FRM 极性的结束地址(Common) LCD_BLK = 1; } void PrintGraphicLogo(stWinAndCur *WinCur, const rom Uchar *Logo, Uint LogoLen) { Uint Li; CharOrGrapMode(0); SetActiveWindow(WinCur->WinLef, WinCur->WinRig, WinCur->WinTop, WinCur->WinBot); GotoXY(WinCur->CurX, WinCur->CurY); for(Li=0; LiVisionOrNo; TempBit2=PtMenu->DispCondition; if(!(TempBit1&0x01)) break; if(TempBit2&0x20) { if(PtMenu->StrLen==0x00) { PageOperate(2, 0, 2); break; } else if(PtMenu->StrLen==0xff) { PageOperate(3, 1, 1); break; } } CharOrGrapMode((TempBit1&0x02) ? 0xff : 0x00); ReverAndBold((TempBit1&0x0c)<<2); FontSize((TempBit1&0xc0)>>6, (TempBit1&0x30)>>4); ASC_ChiAutoSele((TempBit2&0x02) ? 0xff : 0x00); SetActiveWindow(PtMenu->AcWinLef, PtMenu->AcWinRig, PtMenu->AcWinTop, PtMenu->AcWinBot); // GotoXY(PtMenu->StCurX, PtMenu->StCurY); if(TempBit1&0x02) { GotoXY(PtMenu->StCurX, PtMenu->StCurY); for (TB2=0,TB3=PtMenu->StrLen, TemPr=(far rom Uchar *)((*PtMenu).StrPt); TB2<=PtMenu->StrRow; TB2++) { for (; ((*TemPr != '\0')&&(TB3>0)); TemPr++,TB3--) { LCD_DataWrite(*TemPr); } TB3=PtMenu->StrLen; /* if(TempBit2&0x04) GotoXY(PtMenu->StCurX, PtMenu->StCurY+TB2*26); else */ GotoXY(PtMenu->StCurX, PtMenu->StCurY+TB2*29); TemPr=(far rom Uchar *)((*PtMenu).StrPt+TB3*TB2); } }else if (!(TempBit2&0x08)&& (TempBit2&0x10)) { GotoXY(PtMenu->StCurX, PtMenu->StCurY); TB2=PtMenu->StrRow; LcdScreenFill(TB2); }else if (TempBit2&0x08) { GotoXY(PtMenu->StCurX, PtMenu->StCurY+TB2*29); TB2++; for (TB3=PtMenu->StrLen, TemPr=(far rom Uchar *)((*PtMenu).StrPt); TB3>0; TemPr++,TB3--) { LCD_DataWrite(*TemPr); } } } } /*------------------------------------------------ -------------------------- Dplay.H C Display functions. Copyright (c) 2008.03.20 for ?? Ltd. Author : ZMF 2008.03.20 VOL : V0.1 -------------------------------------------------- ------------------------*/ #ifndef _LM2068R_DRIVER_H #define _LM2068R_DRIVER_H #include "LCD_Define.h" extern void LCD_CmdWrite(Uchar cmdReg, Uchar cmdData); extern Uchar LCD_CmdRead(Uchar cmdReg); extern void LCD_DataWrite(Uchar WrData); extern void LCD_ChkBusy(void); extern void LCD_Reset(void); extern void LCD_Initial(void); extern void LcdScreenFill(Uchar SetX); extern void GotoXY(Uchar x1,Uchar y1); extern void CharOrGrapMode(Uchar CharSet); extern void ReverAndBold(Uchar RevBold);//RevBold:bit5bit4:01-R_N_B_Y;10-R_Y_B_N; extern void FontSize(Uchar XSize, Uchar YSize); extern void ASC_ChiAutoSele(Uchar AscSet); extern void SetActiveWindow(Uchar Left, Uchar Right, Uchar Top, Uchar Bottom); extern void PageOperate(Uchar PaMo, Uchar PaOp, Uchar DisPa); extern void PrintGraphicLogo(stWinAndCur *WinCur, const rom Uchar *Logo, Uint LogoLen); extern void PrintLargeLogo( const rom Uchar *Logo,Uint LogoLen); extern void PrintTextOrGraph( far rom DispMenu * PtMenu,Uchar MenuNum); #endif

Linux是一类Unix计算机操作系统的统称。Linux操作系统的的名字也是“Linux”。Linux操作系统也是自由软件和开放源代码发展中最著名的例子。严格来讲,Linux这个词本身只表示Linux内核,但在实际上人们已经习惯了用Linux来形容整个基于Linux内核,并且使用GNU 工程各种工具和数据库的操作系统。Linux得名于计算机业余爱好者Linus Torvalds。

--------转载

阅读(438) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~