單片機源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include<LCD1602.h>
- sbit SS=P1^0;
- sbit MOSI=P1^1;
- sbit SCLK=P1^2;
- sbit INT=P1^3;
- sbit Rec=P1^4;
- sbit Play=P1^5;
- sbit Stop=P1^6;
- sbit Shut=P1^7;
- sbit RecLight=p2^5;
- sbit PlayLight=p2^6;
- sbit WorkLight=P2^7;
- unsigned int n;
- unsigned char count;
- unsigned char code
- POWERUP=0x20,SETPLAY=0xE0,PLAY=0xF0,SETREC=0xA0,REC=0xB0,SETMC=0xE8,MC=0xF8,STOP=0x30,STOPPOWER=0x10;
- unsigned char code speed[]={"speed:"};
- unsigned char code tab[]={"0123456789"};
- void dingshiqi() interrupt 1
- {
- TH0=0x4c;
- TL0=0x00;
- n++;
- }
- void display()
- {
- unsigned char i,count_ge,count_shi,count_bai;
- count=TH1*0X10*0X10+TL1;
- count_ge=(unsigned char)(count%10);
- count_shi=(unsigned char)((count%100)/10);
- count_bai=(unsigned char)(count/100);
- write_com(0x80);
- for(i=0;i<6;i++)
- {
- write_dat(speed[i]);
- }
- write_dat(tab[count_bai]);
- write_dat(tab[count_shi]);
- wirte_dat(tab[count_ge]);
- write_dat('r');
- TH1=0;
- TL1=0;
- n=0;
- }
- void delay(unsigned int i)
- {
- while(i--);
- }
- void Command(unsigned char command,unsigned int address)
- {
- unsigned char i,j;
- SS=1;
- SCLK=0;
- SS=0;
- if(address!=0)
- {
- SS=1;
- SCLK=0;
- SS=0;
- for(i=0;i<16;i++)
- {
- address=_cror_(address,1);
- j=address<<1;
- MOSI=CY;
- SCLK=0;
- delay(3);
- SCLK=1;
- }
- }
- for(i=0;i<8,i++)
- {
- command=_cror_(command,1);
- j=command<<1;
- MOSI=CY;
- SCLK=0;
- delay(3);
- SCLK=1;
- }
- SS=1;
- }
- void main()
- {
- unsigned char a=1:
- P1=0xFF;
- P0=0xFF;
- INT=1;
- lcd_init();
- EA=1;
- ET0=1;
- ET1=1;
- TMOD=0x51;
- TH1=0;
- TL1=0;
- TH0=0x4c;
- TL0=0x00;
- TR0=1;
- TR1=1;
- while(1)
- {
- while(Rec==0)
- {
- delay(3000);
- while (Rec==0)
- {
- RecLight=0;
- PlayLight=1;
- WorkLight=0;
- Command(POWERUP,0);
- delay(6000);
- Command(POWERUP,0);
- delay(6000);
- delay(6000);
- Command(SETREC,0x05);
- Command(REC,0);
- break;
- }
- while (Rec==0){};
- }
- while(Play==0)
- {
- delay(3000);
- while(Play==0)
- {
- PlayLight=0;
- RecLight=1;
- WorkLight=0;
- Command(POWERUP,0);
- delay(6000);
- Command(POWERUP,0);
- delay(6000);
- delay(6000);
- Command(SETPLAY,0x05);
- Command(PLAY,0);
- break;
- }
- while(Play==0){};
- }
- while{Stop==0||INT==0)
- {
- delay(3000);
- while(Stop==0||INT==0)
- {
- PlayLight=1;
- RecLight=1;
- Command(Stop,0);
- a=1;
- break;
- }
- while (Stop==0){};
- }
- while{Shut==0}
- {
- delay(3000);
- while (Shut==0)
- {
- PlayLight=1;
- RecLight=1;
- WorkLight=1;
- Command(STOPPOWER,0)
- break;
- }
- while(Shut==0){};
- }
- if(n==20) display();
- if(count>40&&a==1)
- {
- PlayLight=0;
- RecLight=1;
- WorkLight=0;
- Command(POWERUP,0)
- delay(6000);
- Command(POWERUP,0)
- delay(6000);
- delay(6000);
- Command(SETPLAY,0x05);
- Command(PLAY,0);
- a=0;
- }
- }
- }
復制代碼
所有資料51hei提供下載:
dpj.rar
(6.17 KB, 下載次數: 12)
2018-12-3 15:26 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|