投票表决器源程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
unsigned int yes=0,no=0,qiquan=0,i=0,j=0;
unsigned int temp,succeed=0;
unsigned int y,com,date;
unsigned int ge,shi,bai,a=0;
char y1[8]={2,2,2,2,2,2,2,2},n1[8],y2[7]={2,2,2,2,2,2,2},n2[7];
sbit K1=P1^6; //开关
sbit K2=P1^7; //指示灯
//*****************赞同***************//
sbit D0=P0^0;
sbit D1=P0^1;
sbit D2=P0^2;
sbit D3=P0^3;
sbit D4=P0^4;
sbit D5=P0^5;
sbit D6=P0^6;
sbit D7=P0^7;
sbit DB1=P1^0;
sbit DB2=P1^1;
sbit DB3=P1^2;
sbit DB4=P1^3;
sbit DB5=P1^4;
sbit DB6=P1^5;
sbit rd=P3^7;
//*****************反对**************//
sbit A0=P2^0;
sbit A1=P2^1;
sbit A2=P2^2;
sbit A3=P2^3;
sbit A4=P2^4;
sbit A5=P2^5;
sbit A6=P2^6;
sbit A7=P2^7;
sbit rx=P3^0;
sbit tx=P3^1;
sbit csda=P3^2;
sbit int1=P3^3;
sbit lcden=P3^4;
sbit rs=P3^5;
sbit wr=P3^6;
void delay(unsigned int y) //延时
{
unsigned int a,b;
for(a=y;a>0;a--)
for(b=110;b>0;b--);
}
void write_com(unsigned int com) //写指令
{
rs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(unsigned int date) //写数据
{
rs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
int change(unsigned int a) //把票数转为字符型
{
switch(a)
{
case 0: a=0x30;break;
case 1: a=0x31;break;
case 2: a=0x32;break;
case 3: a=0x33;break;
case 4: a=0x34;break;
case 5: a=0x35;break;
case 6: a=0x36;break;
case 7: a=0x37;break;
case 8: a=0x38;break;
case 9: a=0x39;break;
}
return a;
}
/***********************************1602显示 **/
void xianshi(unsigned int d)
{
// init();
bai=d/100;
shi=(d-100*bai)/10;
ge=d%10;
bai=change(bai);
shi=change(shi);
ge=change(ge);
write_date(bai);
delay(5);
write_date(shi);
delay(5);
write_date(ge);
delay(5);
} //*********************************1602显示 */
void xianshi2() //********显示赞同**//
{
write_date('y');
delay(5);
write_date('e');
delay(5);
write_date('s');
delay(5);
write_date(':');
delay(5);
}
void xianshi3() //*****显示反对****//
{
write_date('n');
delay(5);
write_date('o');
delay(5);
write_date(':');
delay(5);
}
void xianshi4() //******显示弃权*****//
{
write_date('a');
delay(5);
write_date('b');
delay(5);
write_date('s');
delay(5);
write_date('t');
delay(5);
write_date('e');
delay(5);
write_date('n');
delay(5);
write_date('t');
delay(5);
write_date('i');
delay(5);
write_date('o');
delay(5);
write_date('n');
delay(5);
write_date(':');
delay(5);
}
void panduan_yes()
{
if(D0==0)
{
y1[0]=1;
n1[0]=0;
}
if(D1==0)
{
y1[1]=1;
n1[1]=0;
}
if(D2==0)
{
y1[2]=1;
n1[2]=0;
}
if(D3==0)
{
y1[3]=1;
n1[3]=0;
}
if(D4==0)
{
y1[4]=1;
n1[4]=0;
}
if(D5==0)
{
y1[5]=1;
n1[5]=0;
}
if(D6==0)
{
y1[6]=1;
n1[6]=0;
}
if(D7==0)
{
y1[7]=1;
n1[7
]=0;
}
if(DB1==0)
{
y2[0]=1;
n2[0]=0;
}
if(DB2==0)
{
y2[1]=1;
n2[1]=0;
}
if(DB3==0)
{
y2[2]=1;
n2[2]=0;
}
if(DB4==0)
{
y2[3]=1;
n2[3]=0;
}
if(DB5==0)
{
y2[4]=1;
n2[4]=0;
}
if(DB6==0)
{
y2[5]=1;
n2[5]=0;
}
if(rd==0)
{
y2[6]=1;
n2[6]=0;
}
}
void panduan_no()
{
if(A0==0)
{
y1[0]=0;
n1[0]=1;
}
if(A1==0)
{
y1[1]=0;
n1[1]=1;
}
if(A2==0)
{
y1[2]=0;
n1[2]=1;
}
if(A3==0)
{
y1[3]=0;
n1[3]=1;
}
if(A4==0)
{
y1[4]=0;
n1[4]=1;
}
if(A5==0)
{
y1[5]=0;
n1[5]=1;
}
if(A6==0)
{
y1[6]=0;
n1[6]=1;
}
if(A7==0)
{
y1[7]=0;
n1[7]=1;
}
if(rx==0)
{
y2[0]=0;
n2[0]=1;
}
if(tx==0)
{
y2[1]=0;
n2[1]=1;
}
if(csda==0)
{
y2[2]=0;
n2[2]=1;
}
if(int1==0)
{
y2[3]=0;
n2[3]=1;
}
if(lcden==0)
{
y2[4]=0;
n2[4]=1;
}
if(rs==0)
{
y2[5]=0;
n2[5]=1;
}
if(wr==0)
{
y2[6]=0;
n2[6]=1;
}
}
void init() //1602初始化
{
lcden=0;
write_com(0x38);
write_com(0x0e);
write_com(0x01);
write_com(0x80); //为了移动效果
}
void tongji()
{
unsigned int i;
for(i=0;i<8;i++)
{
if(y1[i]==1)
yes++;
if(n1[i]==1)
no++;
if(y1[i]==2)
qiquan++;
}
for(i=0;i<7;i++)
{
if(y2[i]==1)
yes++;
if(n2[i]==1)
no++;
if(y2[i]==2)
qiquan++;
}
}
void restart()
{
unsigned int i;
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
for(i=0;i<8;i++)
{
y1[i]=2;
n1[i]=0;
}
for(i=0;i<7;i++)
{
y2[i]=2;
n2[i]=0;
}
yes=0;
no=0;
qiquan=0;
}
void disp_myname()
{
init(); //1602初始化
write_date('I');
delay(5);
write_date('`');
delay(5);
write_date('m');
delay(5);
write_date(' ');
delay(5);
write_date('C');
delay(5);
write_date('h');
delay(5);
write_date('e');
delay(5);
write_date('n');
delay(5);
write_date(' ');
delay(5);
write_date('Q');
delay(5);
write_date('u');
delay(5);
write_com(0x80+0x40); //写第二行,我的学号
write_date('2');
delay(5);
write_date('0');
delay(5);
write_date('1');
delay(5);
write_date('2');
delay(5);
write_date('0');
delay(5);
write_date('5');
delay(5);
write_date('1');
delay(5);
write_date('4');
delay(5);
write_date('0');
delay(5);
write_date('1');
delay(5);
write_date('3');
delay(5);
write_date('3');
restart();
}
void disp_mydesign()
{
// init(); //1602初始化
write_com(0x80+0x40); //写第二行,显示投票表决器的功能
write_date('V');
delay(5);
write_date('o');
delay(5);
write_date('t');
delay(5);
write_date('i');
delay(5);
write_date('n');
delay(5);
write_date('g');
delay(5);
write_date(' ');
delay(5);
write_date('m');
delay(5);
write_date('a');
delay(5);
write_date('c');
delay(5);
write
_date('h');
delay(5);
write_date('i');
delay(5);
write_date('n');
delay(5);
write_date('e');
delay(5);
restart();
}
void main()
{
K2=0;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
disp_myname(); //显示作者姓名,学号
delay(2000); //2秒后显示本设计名称,投票表决器
disp_mydesign();
while(1)
{
while(K1==1);
EA=0;
K2=1; //计算指示灯
tongji();
init(); //1602初始化
xianshi2();
xianshi(yes);
write_date(' ');
delay(5);
xianshi3();
xianshi(no);
write_com(0x80+0x40);
xianshi4();
xianshi(qiquan);
while(K1==0);
EA=1;
restart();
K2=0;
}
}
void time() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
panduan_yes();
panduan_no();
}