下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 液晶驱动C语言

液晶驱动C语言.

液晶驱动C语言

瓜姐Sandyr8
2019-06-16 0人阅读 举报 0 0 暂无简介

简介:本文档为《液晶驱动C语言doc》,可适用于求职/职场领域

#include"lcdh"#include"fontsh"staticvuTextColor=x,BackColor=xFFFF********************************************************************************FunctionName:DelayLCD*Description:Insertsadelaytime*Input:nCount:specifiesthedelaytimelength*Output:None*Return:None*******************************************************************************voidDelayLCD(un){ui,jfor(i=i<ni)for(j=j<j)}********************************************************************************FunctionName:STMBLCDInit*Description:InitializestheLCD*Input:None*Output:None*Return:None*******************************************************************************voidSTMBLCDInit(void){vudummy=总线配置LCDCtrlLinesConfig()LCDWriteReg(x,x)DelayLCD()LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,xfe)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(xa,x)LCDWriteReg(xb,x)LCDWriteReg(xc,x)LCDWriteReg(xd,x)LCDWriteReg(x,x)LCDWriteReg(x,x)LCDWriteReg(x,xd)LCDWriteReg(x,x)LCDWriteReg(x,x)dummy=LCDReadReg()}********************************************************************************FunctionName:LCDSetTextColor*Description:SetstheTextcolor*Input:Color:specifiestheTextcolorcodeRGB()*Output:TextColor:TextcolorglobalvariableusedbyLCDDrawChar*andLCDDrawPicturefunctions*Return:None*******************************************************************************voidLCDSetTextColor(vuColor){TextColor=Color}********************************************************************************FunctionName:LCDSetBackColor*Description:SetstheBackgroundcolor*Input:Color:specifiestheBackgroundcolorcodeRGB()*Output:BackColor:Backgroundcolorglobalvariableusedby*LCDDrawCharandLCDDrawPicturefunctions*Return:None*******************************************************************************voidLCDSetBackColor(vuColor){BackColor=Color}********************************************************************************FunctionName:LCDClearLine*Description:Clearstheselectedline*Input:Line:theLinetobecleared*Thisparametercanbeoneofthefollowingvalues:*Linex:wherexcanbe*Output:None*Return:None*******************************************************************************voidLCDClearLine(uLine){LCDDisplayStringLine(Line,"")}********************************************************************************FunctionName:LCDClear*Description:ClearstheholeLCD*Input:Color:thecolorofthebackground*Output:None*Return:None*******************************************************************************voidLCDClear(uColor){uindex=LCDSetCursor(x,x)LCDWriteRAMPrepare()*PreparetowriteGRAM*for(index=index<index){LCDWriteRAM(Color)}}********************************************************************************FunctionName:LCDSetCursor*Description:Setsthecursorposition*Input:Xpos:specifiestheXposition*Ypos:specifiestheYposition*Output:None*Return:None*******************************************************************************voidLCDSetCursor(uXpos,uYpos){LCDWriteReg(R,Xpos)LCDWriteReg(R,Ypos)}********************************************************************************FunctionName:LCDDrawChar*Description:DrawsacharacteronLCD*Input:Xpos:theLinewheretodisplaythecharactershape*Thisparametercanbeoneofthefollowingvalues:*Linex:wherexcanbe*Ypos:startcolumnaddress*c:pointertothecharacterdata*Output:None*Return:None*******************************************************************************voidLCDDrawChar(uXpos,uYpos,uc*c){uindex=,i=uXaddress=Xaddress=XposLCDSetCursor(Xaddress,Ypos)for(index=index<index){LCDWriteRAMPrepare()*PreparetowriteGRAM*for(i=i<i){if((cindex(<<i))==x){LCDWriteRAM(BackColor)}else{LCDWriteRAM(TextColor)}}XaddressLCDSetCursor(Xaddress,Ypos)}}********************************************************************************FunctionName:LCDDisplayChar*Description:Displaysonecharacter(dotswidth,dotsheight)*Input:Line:theLinewheretodisplaythecharactershape*Thisparametercanbeoneofthefollowingvalues:*Linex:wherexcanbe*Column:startcolumnaddress*Ascii:characterasciicode,mustbebetweenxandxE*Output:None*Return:None*******************************************************************************voidLCDDisplayChar(uLine,uColumn,uAscii){Ascii=LCDDrawChar(Line,Column,ASCIITableAscii*)}********************************************************************************FunctionName:LCDDisplayStringLine*Description:DisplaysamaximumofcharontheLCD*Input:Line:theLinewheretodisplaythecharactershape*Thisparametercanbeoneofthefollowingvalues:*Linex:wherexcanbe**ptr:pointertostringtodisplayonLCD*Output:None*Return:None*******************************************************************************voidLCDDisplayStringLine(uLine,u*ptr){ui=urefcolumn=while((*ptr!=)(i<)){LCDDisplayChar(Line,refcolumn,*ptr)refcolumn=ptri}}********************************************************************************FunctionName:LCDSetDisplayWindow*Description:Setsadisplaywindow*Input:Xpos:specifiestheXbuttomleftposition*Ypos:specifiestheYbuttomleftposition*Height:displaywindowheight*Width:displaywindowwidth*Output:None*Return:None*******************************************************************************voidLCDSetDisplayWindow(uXpos,uYpos,uHeight,uWidth){if(Xpos>=Height){LCDWriteReg(R,(XposHeight))}else{LCDWriteReg(R,)}LCDWriteReg(R,Xpos)if(Ypos>=Width){LCDWriteReg(R,(YposWidth))}else{LCDWriteReg(R,)}*VerticalGRAMEndAddress*LCDWriteReg(R,Ypos)LCDSetCursor(Xpos,Ypos)}********************************************************************************FunctionName:LCDWindowModeDisable*Description:DisablesLCDWindowmode*Input:None*Output:None*Return:None*******************************************************************************voidLCDWindowModeDisable(void){LCDSetDisplayWindow(,xF,,)LCDWriteReg(R,x)}********************************************************************************FunctionName:LCDDrawLine*Description:Displaysaline*Input:Xpos:specifiestheXposition*Ypos:specifiestheYposition*Length:linelength*Direction:linedirection*Thisparametercanbeoneofthefollowingvalues:Vertical*orHorizontal*Output:None*Return:None*******************************************************************************voidLCDDrawLine(uXpos,uYpos,uLength,uDirection){ui=LCDSetCursor(Xpos,Ypos)if(Direction==Horizontal){LCDWriteRAMPrepare()*PreparetowriteGRAM*for(i=i<Lengthi){LCDWriteRAM(TextColor)}}else{for(i=i<Lengthi){LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)XposLCDSetCursor(Xpos,Ypos)}}}********************************************************************************FunctionName:LCDDrawRect*Description:Displaysarectangle*Input:Xpos:specifiestheXposition*Ypos:specifiestheYposition*Height:displayrectangleheight*Width:displayrectanglewidth*Output:None*Return:None*******************************************************************************voidLCDDrawRect(uXpos,uYpos,uHeight,uWidth){LCDDrawLine(Xpos,Ypos,Width,Horizontal)LCDDrawLine((XposHeight),Ypos,Width,Horizontal)LCDDrawLine(Xpos,Ypos,Height,Vertical)LCDDrawLine(Xpos,(YposWidth),Height,Vertical)}********************************************************************************FunctionName:LCDDrawCircle*Description:Displaysacircle*Input:Xpos:specifiestheXposition*Ypos:specifiestheYposition*Height:displayrectangleheight*Width:displayrectanglewidth*Output:None*Return:None*******************************************************************************voidLCDDrawCircle(uXpos,uYpos,uRadius){sDuCurXuCurYD=(Radius<<)CurX=CurY=Radiuswhile(CurX<=CurY){LCDSetCursor(XposCurX,YposCurY)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurX,YposCurY)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurX,YposCurY)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurX,YposCurY)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurY,YposCurX)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurY,YposCurX)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurY,YposCurX)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)LCDSetCursor(XposCurY,YposCurX)LCDWriteRAMPrepare()*PreparetowriteGRAM*LCDWriteRAM(TextColor)if(D<){D=(CurX<<)}else{D=((CurXCurY)<<)CurY}CurX}}********************************************************************************FunctionName:LCDDrawMonoPict*Description:Displaysamonocolorpicture*Input:Pict:pointertothepicturearray*Output:None*Return:None*******************************************************************************voidLCDDrawMonoPict(uc*Pict){uindex=,i=LCDSetCursor(,)LCDWriteRAMPrepare()*PreparetowriteGRAM*for(index=index<index){for(i=i<i){if((Pictindex(<<i))==x){LCDWriteRAM(BackColor)}else{LCDWriteRAM(TextColor)}}}}********************************************************************************FunctionName:LCDWriteBMP*Description:DisplaysabitmappictureloadedintheinternalFlash*Input:BmpAddress:BmppictureaddressintheinternalFlash*Output:None*Return:None*******************************************************************************voidLCDWriteBMP(uBmpAddress){uindex=,size=size=*(vu*)(BmpAddress)size|=(*(vu*)(BmpAddress))<<index=*(vu*)(BmpAddress)index|=(*(vu*)(BmpAddress))<<size=(sizeindex)BmpAddress=indexLCDWriteReg(R,x)LCDWriteRAMPrepare()for(index=index<sizeindex){LCDWriteRAM(*(vu*)BmpAddress)BmpAddress=}LCDWriteReg(R,x)}********************************************************************************FunctionName:LCDWriteReg*Description:WritestotheselectedLCDregister*Input:LCDReg:addressoftheselectedregister*LCDRegValue:valuetowritetotheselectedregister*Output:None*Return:None*******************************************************************************voidLCDWriteReg(uLCDReg,uLCDRegValue){GPIOB>BRR=xLCDNCSLOW()GPIOB>BRR=xLCDRSLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOC>ODR=LCDRegGPIOWrite(LCDDataPort,LCDReg)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()GPIOC>ODR=LCDRegValueGPIOWrite(LCDDataPort,LCDRegValue)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()}********************************************************************************FunctionName:LCDReadReg*Description:ReadstheselectedLCDRegister*Input:None*Output:None*Return:LCDRegisterValue*******************************************************************************uLCDReadReg(uLCDReg){utempGPIOB>BRR=xLCDNCSLOW()GPIOB>BRR=xLCDRSLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOC>ODR=LCDRegGPIOWrite(LCDDataPort,LCDReg)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()LCDBusIn()GPIOB>BRR=xLCDNRDLOW()temp=GPIOC>IDRtemp=GPIOReadInputData(LCDDataPort)GPIOB>BSRR=xLCDNRDHIGH()LCDBusOut()GPIOB>BSRR=xLCDNCSHIGH()returntemp}********************************************************************************FunctionName:LCDWriteRAMPrepare*Description:PreparetowritetotheLCDRAM*Input:None*Return:None*******************************************************************************voidLCDWriteRAMPrepare(void){GPIOB>BRR=xLCDNCSLOW()GPIOB>BRR=xLCDRSLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOC>ODR=RGPIOWrite(LCDDataPort,R)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()GPIOB>BSRR=xLCDNCSHIGH()}********************************************************************************FunctionName:LCDWriteRAM*Description:WritestotheLCDRAM*Input:RGBCode:thepixelcolorinRGBmode()*Output:None*Return:None*******************************************************************************voidLCDWriteRAM(uRGBCode){GPIOB>BRR=xLCDNCSLOW()GPIOB>BSRR=xLCDRSHIGH()GPIOB>BSRR=xLCDNWRHIGH()GPIOC>ODR=RGBCodeGPIOWrite(LCDDataPort,RGBCode)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()GPIOB>BSRR=xLCDNCSHIGH()}********************************************************************************FunctionName:LCDReadRAM*Description:ReadstheLCDRAM*Input:None*Return:LCDRAMValue*******************************************************************************uLCDReadRAM(void){utempGPIOB>BRR=xLCDNCSLOW()GPIOB>BRR=xLCDRSLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOC>ODR=RGPIOWrite(LCDDataPort,R)GPIOB>BRR=xLCDNWRLOW()GPIOB>BSRR=xLCDNWRHIGH()GPIOB>BSRR=xLCDRSHIGH()LCDBusIn()GPIOB>BRR=xLCDNRDLOW()temp=GPIOC>IDRtemp=GPIOReadInputData(LCDDataPort)GPIOB>BSRR=xLCDNRDHIGH()LCDBusOut()GPIOB>BSRR=xLCDNCSHIGH()returntemp}********************************************************************************FunctionName:LCDPowerOn*Description:PowerontheLCD*Input:None*Output:None*Return:None*******************************************************************************voidLCDPowerOn(void){LCDWriteReg(R,x)LCDWriteReg(R,x)LCDWriteReg(R,x)LCDWriteReg(R,x)DelayLCD()LCDWriteReg(R,xB)LCDWriteReg(R,x)DelayLCD()LCDWriteReg(R,x)DelayLCD()LCDWriteReg(R,xd)LCDWriteReg(R,x)DelayLCD()LCDWriteReg(R,x)}********************************************************************************FunctionName:LCDDisplayOn*Description:EnablestheDisplay*Input:None*Output:None*Return:None*******************************************************************************voidLCDDisplayOn(void){LCDWriteReg(R,x)}********************************************************************************FunctionName:LCDDisplayOff*Description:DisablestheDisplay*Input:None*Output:None*Return:None*******************************************************************************voidLCDDisplayOff(void){LCDWriteReg(R,x)}********************************************************************************FunctionName:LCDCtrlLinesConfig*Description:ConfiguresLCDControllinesPushPullmode*Input:None*Output:None*Return:None*******************************************************************************voidLCDCtrlLinesConfig(void){GPIOInitTypeDefGPIOInitStructureRCCAPBPeriphClockCmd(RCCAPBPeriphGPIOB|RCCAPBPeriphGPIOC,ENABLE)GPIOInitStructureGPIOPin=GPIOPin|GPIOPin|GPIOPin|GPIOPinGPIOInitStructureGPIOSpeed=GPIOSpeedMHzGPIOInitStructureGPIOMode=GPIOModeOutPPGPIOInit(GPIOB,GPIOInitStructure)LCDBusOut()GPIOB>BSRR|=x}********************************************************************************FunctionName:LCDBusIn*Description:ConfigurestheParallelinterfaceforLCD(PortC)*Input:None*Output:None*Return:None*******************************************************************************voidLCDBusIn(void){GPIOInitTypeDefGPIOInitStructureGPIOInitStructureGPIOPin=GPIOPinAllGPIOInitStructureGPIOSpeed=GPIOSpeedMHzGPIOInitStructureGPIOMode=GPIOModeIPUGPIOInit(GPIOC,GPIOInitStructure)}********************************************************************************FunctionName:LCDBusOut*Description:ConfigurestheParallelinterfaceforLCD(PortC)*Input:None*Output:None*Return:None*******************************************************************************voidLCDBusOut(void)GPIOInitTypeDefGPIOInitStructureGPIOInitStructureGPIOPin=GPIOPinAllGPIOInitStructureGPIOSpeed=GPIOSpeedMHzGPIOInitStructureGPIOMode=GPIOModeOutPPGPIOInit(GPIOC,GPIOInitStructure)}********************************************************************************FunctionName:LCDDrawPicture*Description:Displaysacolorpicture*Input:picture:pointertothepicturearray*Output:None*Return:None*******************************************************************************voidLCDDrawPicture(constu*picture){intindexLCDSetCursor(x,x)LCDWriteRAMPrepare()*PreparetowriteGRAM*for(index=index<index){LCDWriteRAM(picture*index<<|picture*index)}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/40

液晶驱动C语言

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利