📄 程序.c
字号:
#include<msp430x14x.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
#define ADCMEM ((int*)0x0140)
uchar key;
uchar total[9],a[6];
unsigned long int Q,sum=0,Lclm=0,Hclm=500000;
unsigned long int resultall=0;
uchar static point1=0,point2=0;
uint times1=1,times2=1;
uint result; //存放A/D转换结果
uint t=0,T=0;
uchar flag=0;
uchar *hzcode;
uchar static code[4]={2,0,0,0};
uchar static password[4]={2,0,0,0};
uchar static set=0;
uchar static right=0;
uchar static yes=0,move=0,i=0,j=0,k=0,x=0;
uchar static r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r8=0;
uchar static codecolum=82,passcolum=82,zerocolum,spancolum;
uchar static zero,span;
uchar static Low[]={0,0,0,0,0,0};
uchar static High[]={5,0,0,0,0,0};
float voltage;
double w,jiao;
uchar dig0[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};
uchar dig1[16]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
uchar dig2[16]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};
uchar dig3[16]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};
uchar dig4[16]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};
uchar dig5[16]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};
uchar dig6[16]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};
uchar dig7[16]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};
uchar dig8[16]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};
uchar dig9[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};
uchar DC[16]={0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00};
uchar DI[16]={0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
uchar DL[26]={0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00};
uchar DN[16]={0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00};
uchar DE[16]={0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00};
uchar DO[16]={0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00};
uchar DP[16]={0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00};
uchar DS[16]={0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00};
uchar DY[16]={0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00};
uchar DZ[16]={0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00};
uchar xd[16]={0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20};
uchar xo[16]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00};
uchar xq[16]={0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80};
uchar xr[16]={0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00};
uchar xt[16]={0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00};
uchar xm[16]={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F};
uchar gang[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
uchar dot[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};
uchar mao[16]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};
uchar fgang[16]={0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00};
uchar blank[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar heng[16]={0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar chin0[32]={
/*-- 文字: 瞬 --*/
0x00,0xFE,0x22,0xFE,0x40,0x32,0xD6,0x9A,0x92,0x16,0x99,0x91,0xF9,0x97,0xB0,0x00,
0x00,0x7F,0x11,0xBF,0x44,0x22,0x15,0x0C,0x03,0x08,0x06,0x04,0xFF,0x04,0x04,0x00
};
uchar chin1[32]={
/*-- 文字: 时 --*/
0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,
0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00
};
uchar chin2[32]={
/*-- 文字: 累 --*/
0x00,0x00,0x00,0x1F,0x95,0xD5,0xB5,0x9F,0x95,0x95,0x55,0x15,0x1F,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x34,0x06,0x46,0x85,0x7C,0x04,0x15,0x26,0x6C,0x00,0x00,0x00
};
uchar chin3[32]={
/*-- 文字: 积 --*/
0x10,0x12,0xD2,0xFE,0x51,0x91,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x81,0x40,0x31,0x0D,0x01,0x01,0x05,0x09,0x31,0xE0,0x00
};
uchar chin4[32]={
/*-- 文字: 流 --*/
0x10,0x60,0x01,0x86,0x60,0x04,0x44,0x64,0x55,0x4E,0x44,0x64,0xC4,0x04,0x04,0x00,
0x04,0x04,0xFC,0x03,0x40,0x30,0x0F,0x00,0x00,0x7F,0x00,0x3F,0x40,0x40,0x70,0x00
};
uchar chin5[32]={
/*-- 文字: 量 --*/
0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5,0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00,
0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F,0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00
};
///////////////////延时程序///////////////////////////////////
void delay(uint dt)
{
uint i;
for(i=0;i<dt;i++);
}
/////////////////////////////写指令程序////////////////////////////
void lcdinswrite(char instruction)
{
uchar i;
P4OUT&=~BIT0;
//片选为0,
P4OUT&=~BIT2; // RS为0
P4OUT&=~BIT3; //CLK=0
for(i=0;i<8;i++)
{
if((instruction&0x80)!=0)
P4OUT|=BIT4; //DB7=1
else
P4OUT&=~BIT4; //DB7=0
P4OUT|=BIT3; //CLK=1
P4OUT&=~BIT3; //CLK=0
instruction= instruction<<1;
}
P4OUT|=BIT0;
//片选为1
}
/////////////////////////////写数据程序////////////////////////////
void lcddatawrite(char data)
{
uchar i;
P4OUT&=~BIT0;
//片选为0,
P4OUT|=BIT2; // RS为1
P4OUT&=~BIT3; //CLK=0
for(i=0;i<8;i++)
{
if((data&0x80)!=0)
P4OUT|=BIT4; //DB7=1
else
P4OUT&=~BIT4; //DB7=0
P4OUT|=BIT3; //CLK=1
P4OUT&=~BIT3; //CLK=0
data=data<<1;
}
P4OUT|=BIT0;
//片选为1
}
////////////////////////写汉字程序/////////////////////////
void dishz1616(uchar x_add,uchar y_add, uchar a[])
{
uchar i,pag,colh,coll;
pag=0xb0|x_add;
colh=0x10+(y_add>>4);
coll=0x00+(y_add&0x0f);
lcdinswrite(pag);
lcdinswrite(colh);
lcdinswrite(coll);
for(i=0;i<32;i++)
{
if(i==16)
{
lcdinswrite(pag+1);
lcdinswrite(colh);
lcdinswrite(coll);
}
lcddatawrite(*a++);
}
}
////////////////////////写数字和字符程序/////////////////////////////
void dishz816(uchar x_add,uchar y_add, uchar a[])
{
uchar i,pag,colh,coll;
pag=0xb0|x_add;
colh=0x10+(y_add>>4);
coll=0x00+(y_add&0x0f);
lcdinswrite(pag);
lcdinswrite(colh);
lcdinswrite(coll);
for(i=0;i<16;i++)
{
if(i==8)
{
lcdinswrite(pag+1);
lcdinswrite(colh);
lcdinswrite(coll);
}
lcddatawrite(*a++);
}
}
///////////////////////////清屏程序////////////////////////////////
void clearLCD(void)
{
uchar x,y;
for(x=0;x<8;x++)
{
lcdinswrite(0xb0|x);
lcdinswrite(0x10);
lcdinswrite(0x00);
for(y=0;y<132;y++)
{
lcddatawrite(0x00);
}
}
}
void clearLCDa(uchar x,uchar y)
{
uchar colh,coll,i;
colh=0x10+(y>>4);
coll=0x00+(y&0x0f);
lcdinswrite(0xb0|x);
lcdinswrite(colh);
lcdinswrite(coll);
for(i=0;i<8;i++)
{
lcddatawrite(0x00);
}
}
////////////////////////液晶屏初始化程序/////////////////////////
void lcdinit(void)
{
P4DIR=0X1F; //P4.0-P4.4设为输出口
P4OUT&=~BIT1; //硬复位 P4.1=0
delay(10);
P4OUT|=BIT1; //P4.1=1
P4OUT|=BIT1;
lcdinswrite(0xe2); //软复位
lcdinswrite(0xa2); //BIAS=1/9
lcdinswrite(0xa1); //列地址移动方向ADC=1,seg132-seg0
lcdinswrite(0xc0);
lcdinswrite(0x2c);
lcdinswrite(0x2e); //行扫描方向SHL=0,com0-com63
lcdinswrite(0x2f); //电源控制模式VC,VR,VF=111
lcdinswrite(0x26); //内部调整电阻比率R2,R1,R0=111
lcdinswrite(0x81); //对比寄存器模式
lcdinswrite(0x10);
lcdinswrite(0xa6);
lcdinswrite(0xa4);
lcdinswrite(0xB0); //页0 1011P3P2P1P0
lcdinswrite(0x40); //设定显示行(COM0) 001ST5ST4ST3ST2ST1ST0
clearLCD();
lcdinswrite(0xaf); //开显示
}
////////////////显示瞬时流量值程序////////////////////////////
void displayQ(void)
{
uchar i,j,a[6],colum=25,first=0;
unsigned long int q;
q=Q;
//clearLCD();
dishz1616(0,4,chin0);
dishz1616(0,20,chin1);
dishz1616(0,36,chin4);
dishz1616(0,52,chin5);
dishz816(0,68,mao);
dishz816(2,96,xm);
dishz816(2,104,dig3);
dishz816(2,112,fgang);
dishz816(2,120,DS);
for(i=0;i<6;i++)
a[i]=0;
i--;
while(q!=0)
{
a[i]=q%10;
q=q/10;
i--;
}
for(j=0;j<6;j++)
{
if(a[j]==0)
{
if(first==1)
hzcode=dig0; //dig0为存储数字0的数组名
else
hzcode=blank;
}
if(a[j]==1)
{
hzcode=dig1;
first=1;
}
if(a[j]==2)
{
hzcode=dig2;
first=1;
}
if(a[j]==3)
{
hzcode=dig3;
first=1;
}
if(a[j]==4)
{
hzcode=dig4;
first=1;
}
if(a[j]==5)
{
hzcode=dig5;
first=1;
}
if(a[j]==6)
{
hzcode=dig6;
first=1;
}
if(a[j]==7)
{
hzcode=dig7;
first=1;
}
if(a[j]==8)
{
hzcode=dig8;
first=1;
}
if(a[j]==9)
{
hzcode=dig9;
first=1;
}
dishz816(2,colum,hzcode);
if(point1!=0)
{ if(5-j==point1)
{
colum=colum+8;
hzcode=dot;
dishz816(2,colum,hzcode);
}
}
colum=colum+8;
}
}
////////////////显示累积流量值程序////////////////////////////
void displaytotal(void)
{
uchar i,j,total[9],colum=18,first=0;
unsigned long int s;
s=sum;
dishz1616(4,2,chin2);
dishz1616(4,18,chin3);
dishz1616(4,34,chin4);
dishz1616(4,50,chin5);
dishz816(4,66,mao);
dishz816(6,114,xm);
dishz816(6,122,dig3);
for(i=0;i<9;i++)
total[i]=0;
i--;
while(s!=0)
{
total[i]=s%10;
s=s/10;
i--;
}
for(j=0;j<9;j++)
{
if(total[j]==0)
{
if(first==1)
hzcode=dig0; //dig0为存储数字0的数组名
else
hzcode=blank;
}
if(total[j]==1)
{
hzcode=dig1;
first=1;
}
if(total[j]==2)
{
hzcode=dig2;
first=1;
}
if(total[j]==3)
{
hzcode=dig3;
first=1;
}
if(total[j]==4)
{
hzcode=dig4;
first=1;
}
if(total[j]==5)
{
hzcode=dig5;
first=1;
}
if(total[j]==6)
{
hzcode=dig6;
first=1;
}
if(total[j]==7)
{
hzcode=dig7;
first=1;
}
if(total[j]==8)
{
hzcode=dig8;
first=1;
}
if(total[j]==9)
{
hzcode=dig9;
first=1;
}
dishz816(6,colum,hzcode);
if(point2!=0)
{
if(8-j==point2)
{
colum=colum+8;
hzcode=dot;
dishz816(6,colum,hzcode);
}
}
colum=colum+8;
}
}
void checkdig(uchar digital)
{
switch(digital)
{
case 0:hzcode=dig0;break;
case 1:hzcode=dig1;break;
case 2:hzcode=dig2;break;
case 3:hzcode=dig3;break;
case 4:hzcode=dig4;break;
case 5:hzcode=dig5;break;
case 6:hzcode=dig6;break;
case 7:hzcode=dig7;break;
case 8:hzcode=dig8;break;
case 9:hzcode=dig9;break;
default:break;
}
}
void discode(void)
{
uchar i,colum;
for(i=0;i<4;i++)
{
if(i==0)
colum=82;
if(i==1)
colum=90;
if(i==2)
colum=98;
if(i==3)
colum=106;
checkdig(code[i]);
dishz816(2,colum,hzcode);
}
dishz816(4,codecolum,heng);
dishz816(4,2,DI);
dishz816(4,10,DN);
dishz816(4,18,gang);
dishz816(4,26,DC);
dishz816(4,34,xo);
dishz816(4,42,xd);
dishz816(4,50,DE);
}
void checkcode(void)
{
uchar i;
for(i=0;i<4;i++)
{
if(code[i]==password[i])
right++;
}
if(right!=4)
{
set=0;
}
right=0;
code[0]=2;
code[1]=0;
code[2]=0;
code[3]=0;
clearLCD();
}
void disnoclr(void)
{
dishz816(2,82,DN);
dishz816(2,90,DO);
dishz816(4,34,DC);
dishz816(4,42,DL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -