献丑了
单片机源程序如下:
- #include<reg51.h>
- #include <intrins.h>
- sbit Sound=P0^0;//嘀嘀嘀
- sbit car1=P0^1;
- sbit car2=P0^2;
- sbit car3=P0^3;
- sbit car4=P0^4;
- sbit LEDARRAY_CLK = P0^5;
- sbit LEDARRAY_LE = P0^6;
- sbit LEDARRAY_DI = P0^7;//点阵
- bit flag;
- unsigned char led_8;
- unsigned char js;
- unsigned char code xin[]={0x0C,0x1E,0x3E,0x7C,0x7C,0x3E,0x1E,0x0C};
- unsigned char code jin[]={0x00,0x00,0x42,0x82,0x7e,0x02,0x02,0x00};
- unsigned char code xiao[]={0x84,0x42,0x24,0x18,0x18,0x24,0x42,0x80};
- unsigned char code qian[]={0x00,0x1e,0x21,0x21,0x31,0x21,0x5e,0x40};
- unsigned char code black[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- void delay(unsigned char t)
- {
- unsigned int m;
- for(;t>0;t--)
- for(m=5000;m>0;m--);
- }
- /*-------------函数声明-----------*/
- void sport(unsigned char sport);
- void Send_Byte( unsigned char dat);
- void disply(unsigned char code *p);
- /*=*=*=*=*=*=*=*=*=*=*主--函--数=*=*=*=*=*=*=*=*=*=*=*/
- void main ()
- {
- unsigned char LED;
- TMOD=0X20; //设置定时器1工作方式2,八位自动重装
- TH1=0Xfd;
- TL1=0Xfd; //设定9600波特率
- TR1=1; //启动定时器
- REN=1; //允许串行口接收控制位
- SM0=0;
- SM1=1; //设定串行口工作方式1
- EA=1; //总中断控制位打开
- ES=1; //串行口中断控制位打开
- Sound=1;
- car1=0;
- car2=0;
- car3=0;
- car4=0;
- led_8=0x1f;
- flag=0;LED=1;
- while(1)
- {
- L:
- if(flag==1)
- {
- LED=~LED;
- disply(black);
- P1=0Xff;
- flag=0;
- }
- if(LED==1)
- {
- disply(xin);if(flag==1) goto L;
- disply(jin);if(flag==1) goto L;
- disply(xiao);if(flag==1) goto L;
- disply(qian);
- }
- }//while
- }//main
- /*=================串口中断程序=================*/
- void serial() interrupt 4
- {
- RI=0; //清零,准备接收数据
- js=SBUF; //接收数据
- sport(js); //运动控制
- }
- /*=====================================================
- ---------运动调节函数---------
- =====================================================*/
- void sport(unsigned char sport)
- {
- switch(sport)
- {
- case 0x41: car1=1;car2=0;car3=0;car4=1; break;/////////////方向键 A
- case 0x42: car1=0;car2=1;car3=1;car4=0; break;/////////////方向键 B
-
- case 0x43: car1=1;car2=1;car3=1;car4=1; break;/////////////暂停键 C
- case 0x44: car1=0;car2=1;car3=0;car4=1; break;/////////////后退键 D
- case 0x45: car1=1;car2=0;car3=1;car4=0; break;/////////////前进键 E
- case 0x46: Sound=1; break;/////////////喇叭响 F
- case 0x47: Sound=0; break;/////////////喇叭静 G
-
- case 0x48: flag=1; break;/////////////开灯 H
- default: break;
- }
-
- }
- /*=====================================================
- ---------点阵发送一个字节---------
- =====================================================*/
- void Send_Byte( unsigned char dat)
- {
- unsigned char i;
- LEDARRAY_LE = 0;
- _nop_();
- LEDARRAY_LE = 0;
- _nop_();
- for( i = 0 ; i < 8 ; i++ )
- {
- if( dat&0x01 )
- {
- LEDARRAY_DI = 1;
- }
- else
- {
- LEDARRAY_DI = 0;
- }
-
- LEDARRAY_CLK = 1; //上升沿发送数据
- _nop_();
- LEDARRAY_CLK = 0;
- _nop_();
-
- dat >>= 1;
- }
- }
- void disply(unsigned char code *p)
- {
- unsigned char *led;
- unsigned char temp;
- unsigned int i;
- unsigned char j;
- temp = 0x7f;
-
- for(i=1800;i>0;i--)
- {
- led=p;
- for(j=0;j<8;j++)
- {
- Send_Byte(temp); //列选择
- Send_Byte(*led); //行数据
-
- LEDARRAY_LE = 1; //锁存数据
- _nop_();
- LEDARRAY_LE = 0;
- _nop_();
-
- temp=_cror_(temp,1);
- led++;
- }
-
- if(i==1800||i==1600||i==1400||i==1200||i==1000||i==800||i==600||i==400||i==200)
- {
- led_8=_cror_(led_8,1);
- P1=led_8;
- }
- }
- }
复制代码
所有资料51hei提供下载:
_QQ_小车.rar
(113.94 KB, 下载次数: 4)
|