参加比赛的作品,智能停车装置,实物图片没了。只剩下程序了
单片机源程序如下:
- #include"key.h"
- #include"12864.h"
- #include"delay.h"
- #include"bjdj.h"
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char TL0_temp; /*暂存TL0的初值*/
- unsigned char TH0_temp,count; /*暂存TH0的初值*/
- #define CRY_FREQUENCY 11059200 /*CRY_FREQUENCY为晶振频率,单位为Hz*/
- #define INT_CLOCK 100 /*INT_CLOCK为定时值,单位为ms ,此处定义为10ms*/
- uchar nmm[6]; //每次MCU采集到的密码输入
- uchar wei,key;
- unsigned char count1,count2,jd1,jd2; //0.5ms次数标识
- uchar tcw1[6]={0,0,0,0,0,0};
- uchar tcw2[6]={0,0,0,0,0,0};
- uchar tcw3[6]={0,0,0,0,0,0};
- uchar tcw4[6]={0,0,0,0,0,0};
- uchar tcw5[6]={0,0,0,0,0,0};
- uchar tcw6[6]={0,0,0,0,0,0};
- uchar tcw[6]={0,0,0,0,0,0};
- bit allow,genggai,ok,wanbi,retry,close,cbw; //各个状态位
- uchar global_state = 0;
- uchar count_num = 0; //输入的数字个数
- sbit dula=P2^6;
- sbit pwm1=P1^1;
- sbit pwm2=P1^2;
- sbit wela = P2^7; //代表锁控的继电器IO 高电平关锁,低电平开锁
- //sbit LEDRED = P3^3; //代表密码输入错误的红灯IO 高电平熄灭,低电平点亮
- //sbit LEDGREEN = P3^4; //代表密码输入正确的绿灯IO 高电平熄灭,低电平点亮
- uchar genPasswd[6]; //存储生成的四位随机数密码
- uchar inpPasswd[6]; //存储取包时输入的四位密码
- void Timer0_init()
- {
- unsigned long T0_temp; /*暂存T0的初始值 */
- T0_temp = 65536-((INT_CLOCK *CRY_FREQUENCY /1000)/12); /*T0初始值计算公式,参考教科书*/
- TL0_temp = T0_temp & 0xff;
- TH0_temp = T0_temp >> 8;
- TL0 = TL0_temp;
- TH0 = TH0_temp;
- TMOD |= 0x01;
- TR0 = 1; /*开定时器0中断*/
- ET0 = 1;
- EA = 1; /*开总中断*/
- }
- void Time1_Init()
- {
- TMOD |= 0x10;
- ET1=1;
- TH1 = 0x0FF;
- TL1 = 0x0A4;
- TR1=1;
- }
- void main()
- {
- uchar i,z,bl,b2;
- uint passwd;
- uchar tcwa,tcwb,tcwc,tcwd,tcwe,tcwf,tcwz;
- uchar key_value = 0;
- uchar temp_key_value = 0xff;
- jd1=13;
- jd2=30;
- count1=0;
- count2=0;
- xa=0;
- xb=0;
- xc=0;
- xd=0;
- ya=0;
- yb=0;
- yc=0;
- yd=0;
- Timer0_init(); //定时器初始化
- Time1_Init();
- lcd_init(); //LCD12864初始化
- while(1) //进入不断循环
- {
- temp_key_value = Calkey_scan(); //读取矩阵按键的键值
- if(temp_key_value != 0xff)
- {
- key_value = temp_key_value;
- }
- switch(global_state)
- {
- case 0: //初始化状态
- display(2,1," 欢迎使用 "); //显示欢迎语句 -- "welcome"
- display(3,1,"自行车智能停车库");
- for(i = 0;i < 6;i++)
- inpPasswd[i] = ' '; //清除刚刚输入的密码
- if(key_value == 13) //存包按键被按下
- {
- key_value = 0xff; //将按键值清除
- // Lock = 0; //开锁
- for(i=0;i<6;i++)
- {
- if(tcw[i]==0) break;
- }
- passwd =TL0; //采用定时器寄存器的值作为密码
- genPasswd[0] = passwd%100/10+0X30; //存储密码
- genPasswd[1] = passwd%10+0X30;
- passwd =TL0; //采用定时器寄存器的值作为密码
- genPasswd[2] = passwd%100/10+0X30;
- genPasswd[3] = passwd%10+0X30;
- passwd =TH0; //采用定时器寄存器的值作为密码
- genPasswd[4] = passwd%100/10+0X30;
- genPasswd[5] = passwd%10+0X30;
- write_com(0x01);
- delay_ms(5);
- switch(i)
- {
- case 0: for(z=0;z<6;z++)
- {
- tcw1[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=1;
- break;
- case 1: for(z=0;z<6;z++)
- {
- tcw2[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=2;
- break;
- case 2: for(z=0;z<6;z++)
- {
- tcw3[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=3;
- break;
- case 3: for(z=0;z<6;z++)
- {
- tcw4[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=4;
- break;
- case 4: for(z=0;z<6;z++)
- {
- tcw5[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=5;
- break;
- case 5: for(z=0;z<6;z++)
- {
- tcw6[z]=genPasswd[z];
- }
- tcw[i]=1+0x30;
- global_state = 1; //切换运行状态
- bl=6;
- break;
- case 6: display(2,3,"车位已满");
- global_state = 0;
- delay_ms(1900);
- break;
- }
- //display(1,1,"正在停车"); //显示关门提示语 -- "正在停车"
- //delay_ms(1900); //等待关门 大约3秒
- // Lock = 1; //关门
-
- }
- if(key_value == 14) //取包按键被按下
- {
- key_value = 0xff; //将按键值清除
- global_state = 2; //切换运行状态
- count_num = 0; //清除数字按键变量
- write_com(0x01);
- delay_ms(5);
- display(2,2,"请输入密码"); //显示输入密码界面
- //display(2,1," ");
- for(i = 0;i < 6;i++) //清空输入的密码数组
- inpPasswd[i] = ' ';
- }
- break;
- case 1: //密码生成状态
- write_com(0x01);
- delay_ms(5);
- display(2,2,"请牢记密码"); //显示密码生成界面Passwd
- display(3,3,genPasswd);
- switch(bl)
- {
- case 3: jd1=10;
- jd2=33;
- zuobiaojy(140);
- gaodu2(35);
- zuobiaox(92);
- gaodu1(35);
- jd1=21;
- jd2=22;
- gaodu2(35);
- zuobiaojx(92);
- jd1=13;
- jd2=30;
- gaodu1(35);
- zuobiaoy(142);
- break;
- case 4: jd1=10;
- jd2=33;
- zuobiaojy(132);
- gaodu2(35);
- zuobiaojx(88);
- gaodu1(35);
- jd1=21;
- jd2=22;
- gaodu2(35);
- zuobiaox(88);
- jd1=13;
- jd2=30;
- gaodu1(35);
- zuobiaoy(132);
- break;
- case 1: jd1=10;
- jd2=33;
- zuobiaojy(137);
- gaodu2(150);
- zuobiaox(95);
- gaodu1(27);
- jd1=21;
- jd2=22;
- gaodu2(27);
- zuobiaojx(95);
- jd1=13;
- jd2=30;
- gaodu1(150);
- zuobiaoy(190);
- break;
- case 2: jd1=10;
- jd2=33;
- zuobiaojy(125);
- gaodu2(148);
- zuobiaojx(93);
- gaodu1(23);
- jd1=21;
- jd2=22;
- gaodu2(23);
- zuobiaox(93);
- jd1=13;
- jd2=30;
- gaodu1(148);
- zuobiaoy(180);
- break;
- case 5: jd1=10;
- jd2=33;
- zuobiaojy(394);
- gaodu2(148);
- zuobiaojx(88);
- gaodu1(23);
- jd1=21;
- jd2=22;
- gaodu2(23);
- zuobiaox(88);
- jd1=13;
- jd2=30;
- gaodu1(148);
- zuobiaoy(394);
- break;
- case 6: jd1=10;
- jd2=33;
- zuobiaojy(394);
- gaodu2(148);
- zuobiaojx(88);
- gaodu1(23);
- jd1=21;
- jd2=22;
- gaodu2(23);
- zuobiaox(88);
- jd1=13;
- jd2=30;
- gaodu1(148);
- zuobiaoy(394);
- break;
- }
- bl=0;
- write_com(0x01);
- delay_ms(5);
- global_state = 0; //返回到初始界面
-
- break;
- case 2: //输入密码状态
-
- display(3,3,inpPasswd); //显示输入密码界面
- if((key_value >= 0) && (key_value <= 9)) //如果按下的为0-9的数字按键
- {
-
- if(count_num <= 5) //如果按键次数小于6次
- {
- inpPasswd[count_num] = key_value+0X30; //将按键值存入数组,并显示
- count_num++;
- }
- key_value = 0xff; //将按键值清除
- }
- if(key_value == 15) //清除按键被按下
- {
- key_value = 0xff; //将按键值清除
- count_num=0;
- for(i = 0;i < 6;i++)
- inpPasswd[i] = ' '; //清除刚刚输入的密码
- }
- if(key_value == 16) //确认按键被按下
- {
- key_value = 0xff; //将按键值清除
- for(tcwa = 0;tcwa < 6;tcwa++) //判断密码是否正确,判断车辆位置
- {
- if(tcw1[tcwa] != inpPasswd[tcwa])
- break;
- }
- for(tcwb = 0;tcwb < 6;tcwb++)
- {
- if(tcw2[tcwb] != inpPasswd[tcwb])
- break;
- }
- for(tcwc = 0;tcwc < 6;tcwc++)
- {
- if(tcw3[tcwc] != inpPasswd[tcwc])
- break;
- }
- for(tcwd = 0;tcwd < 6;tcwd++)
- {
- if(tcw4[tcwd] != inpPasswd[tcwd])
- break;
- }
- for(tcwe = 0;tcwe < 6;tcwe++)
- {
- if(tcw5[tcwe] != inpPasswd[tcwe])
- break;
- }
- for(tcwf = 0;tcwf < 6;tcwf++)
- {
- if(tcw6[tcwf] != inpPasswd[tcwf])
- break;
- }
- write_com(0x01);
- delay_ms(5);
- if(tcwa==6)
- {
- tcwz=1;
- tcw[1]=0;
- display(2,1,"一号车位已出车 ");
- b2=1;
- }
- if(tcwb==6)
- {
- tcwz=2;
- tcw[2]=0;
- display(2,1,"二号车位已出车 ");
- b2=2;
- }
- if(tcwc==6)
- {
- tcwz=3;
- tcw[3]=0;
- display(2,1,"三号车位已出车 ");
- b2=3;
- }
- if(tcwd==6)
- {
- tcwz=4;
- tcw[4]=0;
- display(2,1,"四号车位已出车 ");
- b2=4;
- }
- if(tcwe==6)
- {
- tcwz=5;
- tcw[5]=0;
- display(2,1,"五号车位已出车 ");
- b2=5;
- }
- if(tcwf==6)
- {
- tcwz=6;
- tcw[6]=0;
- display(2,1,"六号车位已出车 ");
- b2=6;
- }
- if(tcwz==0)
- {
- display(2,3,"密码错误");
- delay_ms(2000);
- }
- switch(b2)
- {
- case 3:
- zuobiaojy(140);
- gaodu2(35);
- jd1=21;
- jd2=22;
- zuobiaox(92);
- gaodu1(35);
- jd1=10;
- jd2=33;
-
- gaodu2(35);
- zuobiaojx(92);
-
- gaodu1(35);
- zuobiaoy(142);
- jd1=13;
- jd2=30;
- break;
- case 4:
- zuobiaojy(132);
- gaodu2(35);
- jd1=21;
- jd2=22;
- zuobiaojx(88);
- gaodu1(35);
- jd1=10;
- jd2=33;
- gaodu2(35);
- zuobiaox(88);
- gaodu1(35);
- zuobiaoy(132);
- jd1=13;
- jd2=30;
- break;
- case 1: zuobiaojy(137);
- gaodu2(150);
- jd1=21;
- jd2=22;
- zuobiaox(95);
- gaodu1(27);
- jd1=10;
- jd2=33;
- gaodu2(27);
- zuobiaojx(95);
- gaodu1(150);
- zuobiaoy(190);
- jd1=13;
- jd2=30;
- break;
- case 2:
- zuobiaojy(125);
- gaodu2(148);
- jd1=21;
- jd2=22;
- zuobiaojx(93);
- gaodu1(23);
- jd1=10;
- jd2=33;
- gaodu2(23);
- zuobiaox(93);
- gaodu1(148);
- zuobiaoy(180);
- jd1=13;
- jd2=30;
- break;
- case 5:
- zuobiaojy(394);
- gaodu2(148);
- jd1=21;
- jd2=22;
- zuobiaojx(88);
- gaodu1(23);
- jd1=10;
- jd2=33;
-
- gaodu2(23);
- zuobiaox(88);
-
- gaodu1(148);
- zuobiaoy(394);
- jd1=13;
- jd2=30;
- break;
- case 6:
- zuobiaojy(394);
- gaodu2(148);
- jd1=21;
- jd2=22;
- zuobiaojx(88);
- gaodu1(23);
- jd1=10;
- jd2=33;
-
- gaodu2(23);
- zuobiaox(88);
-
- gaodu1(148);
- zuobiaoy(394);
- jd1=13;
- jd2=30;
- break;
- }
- b2=0;
- global_state = 0; //返回到初始界面
- write_com(0x01);
- delay_ms(5);
- }
-
- break;
- }
- }
- }
- void T0_interrupt(void) interrupt 1
- {
- TH0 += TH0_temp;
- TL0 += TL0_temp;
- }
- void Time1_Int()interrupt 3
- {
- TH1 = 0x0FF;
- TL1 = 0x0A4;
- if(count1<jd1)
- pwm1=1;
- else
- pwm1=0;
- if(count2<jd2)
- pwm2=1;
- else
- pwm2=0;
- count1=(count1+1);
- count1=count1%200; //对40取余是为了保持20ms周期
- count2=(count2+1);
- count2=count2%200; //对40取余是为了保持20ms周期
- }
复制代码
所有程序51hei提供下载:
智能停车.zip
(105.14 KB, 下载次数: 7)
|