//#define a 0b00000010
//#define b 0b00001000
#define a 0b01000000 //另一段
#define b 0b00100000 //另一段
#define c 0b01000000
#define d 0b10000000
#define e 0b00100000
#define f 0b00000100
#define g 0b00010000
#define none 0x00000000
#define LCD_MASK0 0xff
#define LCD_MASK1 0xff
#define LCD_MASK2 0xff
/*LCD取模:xDCEGFBA*/ /* 0 1 2 3 4 5 6 7 8 9*/
//const unsigned char LCD_MODEL[11]={0x77,0x22,0x5b,0x6b,0x2e,0x6d,0x7d,0x23,0x7f,0x6f,0x00};
const unsigned int LCD_MODEL[10][2]={
{a,b+c+d+e+f}, //0
{b,c}, //1
{a+b,d+e+g}, //2
{a+b,c+d+g}, //3
{b,f+c+g}, //4
{a,f+c+d+g}, //5
{a,f+c+d+e+g}, //6
{a+b,c}, //7
{a+b,f+c+d+e+g}, //8
{a+b,f+c+d+g} //9
} ;
/*LCD初始化函数*/
void Init_LCD(void)
{
/*COM0*/
LCDDATA0=0x00;
LCDDATA1=0x00;
/*COM1*/
LCDDATA3=0x00;
LCDDATA4=0x00;
/*COM2*/
LCDDATA6=0x00;
LCDDATA7=0x00;
/*COM3*/
LCDDATA9=0x00;
LCDDATA10=0x00;
/*SEG0-SEG14使能*/
LCDSE0=0xff;
LCDSE1=0x7f;
/*使能LCD驱动模块,休眠模式下禁止LCD驱动模块,无LCD写错误,使能VLCD引脚*/
/*时钟选择FOSC/8192,公共端选择1/4(COM<3:0>)*/
LCDCON=0xd3;//0xd3;
/*B型波形,1/3偏置模式,使能LCD驱动模块,允许写入LCDDATAx寄存器*/
/*LCD预分频比选择位:LP<3:0>=0010=1:3,LCD帧频率=64Hz*/
LCDPS=0xb3;//0xb3;
}
void Lcd_Show0(char Data)
{
LCDDATA0=(LCDDATA0&~LCD_MASK0)|LCD_MODEL[Data][1];//<<3);
LCDDATA1=(LCDDATA1&~LCD_MASK0)|LCD_MODEL[Data][0];
LCDDATA2=0;
}
void Lcd_Show1(char Data)
{
LCDDATA3=(LCDDATA3&~LCD_MASK0)|LCD_MODEL[Data][1];//<<2);
LCDDATA4=(LCDDATA4&~LCD_MASK0)|LCD_MODEL[Data][0];
LCDDATA5=0;
}
void Lcd_Show2(char Data)
{
LCDDATA6=(LCDDATA6&~LCD_MASK0)|LCD_MODEL[Data][1];//<<1);
LCDDATA7=(LCDDATA7&~LCD_MASK0)|LCD_MODEL[Data][0];
LCDDATA8=0;
}
void Lcd_Show3(char Data)
{
LCDDATA9 =(LCDDATA9&~LCD_MASK0) |LCD_MODEL[Data][1];//<<0);
LCDDATA10=(LCDDATA10&~LCD_MASK0)|LCD_MODEL[Data][0];
LCDDATA11=0;
}
/*LCD显示函数,显示范围-1999~1999*/
void LCDNUMI(int num)
{
unsigned char ge,s,ba,q;//ge=0,s=0,ba=0;/*个位,十位,百位*/
q=num %10000/1000;
ba=num %1000/100;
s=num %100/10;
ge=num %10;
Lcd_Show3(ge);
Lcd_Show2(s);
Lcd_Show1(ba);
Lcd_Show0(q);
}
void delay(int i)
{
while(i>0)
{
i--;
}
}
void main(void)
{
int num=1234;//-1999;
OSCCON = 0b01110001; //8MHz内部晶振
while(!HTS); //等待主时钟稳定// while(!(OSCCON&0x04));
Init_LCD();
while(1)
{
LCDNUMI(num);//只能显示第一位
// num++;
delay(65000);
}
}