新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC16F913驅(qū)動(dòng)LCD proteus仿真

PIC16F913驅(qū)動(dòng)LCD proteus仿真

作者: 時(shí)間:2016-11-11 來(lái)源:網(wǎng)絡(luò) 收藏
#include

void InitLCD(void);
void InitPort(void);
void LCDDigital_Disp(unsigned char dignum,unsigned char dispnum);
void LCDDisplayFunc(unsigned char buff1,unsigned char buff2,unsigned char buff3);
void main(void)
{
OSCCON=0x67; //int osc 8MHz
InitPort();
InitLCD();
LCDDisplayFunc(3,6,9);
while(1)
{

本文引用地址:http://2s4d.com/article/201611/316735.htm

}
}

void InitPort(void)
{
PORTA=0x00;
PORTB=0;
PORTC=0;
TRISA=0;
TRISB=0;
TRISC=0;
RC4=0;
RC5=0;
RB7=0;
RB6=1;
}

void InitLCD(void)
{
LCDPS=0x30;
LCDSE0=0xff; //LCDSEn for SEGn control
LCDSE1=0x03; //SEG15 not in use at 1/4 duty
//LCDSE2=0xff;
LCDCON=0x83;
PIR2=0x00;
}

/***********************************************************
//Function Name: LCDDigital_Disp
//Function Description: display the number at specified position
//Input Parameter: dignum,dispnum
//Output Parameter: none
//Note: none
***********************************************************/

void LCDDigital_Disp(unsigned char dignum,unsigned char dispnum)
{
switch(dispnum) //d dot c e g f b a
{
case 0 : //0xb7
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x01<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x03<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x01<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x03<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x01<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x03<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 1 : //0x22
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x02<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x00<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x00<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x02<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x00<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x00<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x02<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x00<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x00<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 2 : //0x9b
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x02<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x01<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x02<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x01<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x02<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x01<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 3 : //0xab
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x02<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x02<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x02<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 4 : //0x2e
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x02<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x03<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x00<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x02<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x03<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x00<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x02<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x03<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x00<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 5 : //0xad
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x01<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x03<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x01<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x03<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x01<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x03<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 6 : //0xbd
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x01<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x03<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x03<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x01<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x03<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x03<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x01<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x03<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x03<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 7 : //0x23
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x00<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x00<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x00<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x00<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x00<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x00<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 8 : //0xbf
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x03<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x03<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x03<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x03<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x03<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x03<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 9 : //0xaf
if(1==dignum)
{
LCDDATA0=(LCDDATA0&~0x0c)|(0x03<<2); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x0c)|(0x03<<2); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x0c)|(0x02<<2); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x04)|(0x02<<1); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0=(LCDDATA0&~0x30)|(0x03<<4); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0x30)|(0x03<<4); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0x30)|(0x02<<4); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x10)|(0x02<<3); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0=(LCDDATA0&~0xc0)|(0x03<<6); //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3=(LCDDATA3&~0xc0)|(0x03<<6); //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6=(LCDDATA6&~0xc0)|(0x02<<6); //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9=(LCDDATA9&~0x40)|(0x02<<5); //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
case 10 : //NULL
if(1==dignum)
{
LCDDATA0&=~0x0c; //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3&=~0x0c; //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6&=~0x0c; //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9&=~0x04; //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(2==dignum)
{
LCDDATA0&=~0x30; //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3&=~0x30; //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6&=~0x30; //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9&=~0x10; //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
if(3==dignum)
{
LCDDATA0&=~0xc0; //|3b|3a|2b|2a|1b|1a|DH|rc|
LCDDATA3&=~0xc0; //|3g|3f|2g|2f|1g|1f|RH|bat|
LCDDATA6&=~0xc0; //|3c|3e|2c|2e|1c|1e|dig0|negative sign|
LCDDATA9&=~0x40; //|-|3d|dot3|2d|dot2|1d|dot1|AC|
}
break;
default :
break;
}
}

/***********************************************************
//Function Name: LCDDisplayFunc
//Function Description: Display the content of the dispbuff
//Input Parameter: buff1 buff2 buff3
//Output Parameter: none
//Note: 0<=buff<=9 display blank when buff=10
***********************************************************/

void LCDDisplayFunc(unsigned char buff1,unsigned char buff2,unsigned char buff3)
{
LCDDigital_Disp(1,buff1);
LCDDigital_Disp(2,buff2);
LCDDigital_Disp(3,buff3);
}

附:proteus仿真圖片



評(píng)論


技術(shù)專區(qū)

關(guān)閉