PIC16F913驱动LCD proteus仿真
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)
{
}
}
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;
}
}
PIC16F913驱动LCDproteus仿 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)