|
公交車報站系統的仿真,msp430f2272為中央處理器的鍵盤掃描,led驅動,7段數碼管的控制。isd1420的驅動在proteus仿真的原理圖,以及源程序。
單片機代碼:
- /* Main.c file generated by New Project wizard
- *
- * Created: 周一 六月 20 2016
- * Processor: MSP430F2272
- * Compiler: CodeComposer for MSP430
- */
- #include <msp430.h>
- void main()
- { #include <msp430f2272.h>
- #define CPU_F ((double)8000000)
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- void Clock_Init()
- {
- unsigned char i;
- BCSCTL1&=~XT2OFF; //打開XT2振蕩器
- BCSCTL2|=SELM1+SELS; //MCLK為8MHZ,SMCLK為8MHZ
- do
- {
- IFG1&=~OFIFG; //清除振蕩器錯誤標志
- for(i=0;i<100;i++)
- _NOP();
- }
- while((IFG1&OFIFG)!=0); //如果標志位1,則繼續循環等待
- IFG1&=~OFIFG;
- }
- int main(void)
- {
- WDTCTL = WDTPW + WDTHOLD;
- Clock_Init();
- P1REN|=0xff; //按鍵初始化
- P1OUT |=0xff;
- P2DIR |= 0x0F; //控制端口初始化
- P2OUT |= BIT0+BIT1+BIT2;
- P3DIR |= 0xff; //LED控制端口
- P4DIR |= 0xff; //語音地址端口初始化
- unsigned int dz1[]={0x50,0x48};
- unsigned int dz2[]={0x60};
- unsigned int dz3[]={0x68};
- unsigned int dz4[]={0x88};
- unsigned int dz5[]={0x70};
- unsigned int dz6[]={0x58};
- unsigned int dz7[]={0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40};
- unsigned int counter1=0; // ISD地址計數器
- unsigned int temp;
- unsigned int flag = 0; //正反選擇標志
- unsigned int counter3 = 0; //正反計數器
- unsigned int buff2[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
- unsigned int counter2=0 ; // LED地址計數器
- P3OUT = buff2[counter2];
- unsigned int counter4=0; //錄音計數器
- while(1)
- {
- if ((P1IN & BIT0) == 0) // 錄音模式
- {
- P2OUT&=~BIT0 ;
- counter4++;
- if(counter4<=14)
- {
- delay_ms(999);
- P2OUT |= BIT0;
- }
- if(counter4>14)
- {
- delay_ms(2999);
- P2OUT |= BIT0;
- }
- while(((P1IN & BIT0) == 0) );
- }
- while ((P1IN & BIT1) == 0) // 放音模式
- {
- while((flag==0)&((P1IN & BIT1) == 0))
- {
- if ((P1IN&BIT3)==0) // 報站
- {
- pl1:
- P3OUT|=BIT7;
- counter2++;
- P3OUT = buff2[counter2]+BIT7;
- if(counter1==0)
- {
- P2OUT&=~BIT1;
- P4OUT=dz1[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz2[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz3[3];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz4[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- if((8!=counter1)&(0!=counter1))
- {
- P2OUT&=~BIT1;
- P4OUT=dz7[counter1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz6[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz5[0];
- delay_ms(3000);
- P2OUT&=~BIT1;
- P4OUT = dz2[0];
- delay_ms(1000);
- counter1++;
- temp = counter1;
- counter1--;
- P2OUT&=~BIT1;
- P4OUT = dz7[temp];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz3[3];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[temp];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz4[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- if(counter1==8)
- {
- P2OUT&=~BIT1;
- P4OUT=dz1[1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT=dz7[counter1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT=dz6[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz5[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- counter1++;
- while((P1IN&BIT3)==0);
- while((P1IN&BIT5)==0);
- P3OUT&=~BIT7;
- }
- if ((P1IN & BIT4) == 0) // 回退
- {
- counter1--;
- counter2--;
- P3OUT = buff2[counter2];
- while((P1IN&BIT4)==0);
- }
- if ((P1IN & BIT5) == 0) // 重復報站
- {
- P2OUT&=~BIT1;
- counter1--;
- counter2--;
- goto pl1;
- }
- if ((P1IN & BIT6) == 0) // 復位
- {
- counter1=0;
- counter2=0;
- P3OUT = buff2[counter2];
- while((P1IN&BIT6)==0);
- }
- if ((P1IN & BIT2) == 0) // 正反選擇
- {
- counter3++;
- if((counter3%2)==0)
- {
- flag = 0;
- P2OUT |=BIT2;
- counter1=0;
- counter2=0;
- }
- if((counter3%2)==1)
- {
- flag = 1;
- P2OUT &= ~BIT2;
- counter1=8;
- counter2=10;
- }
- while((P1IN&BIT2)==0);
- }
- }
- while((flag==1)&((P1IN & BIT1) == 0))
- {
- if ((P1IN&BIT3)==0) // 報站
- {
- pl2:
- P3OUT|=BIT7;
- counter2--;
- P3OUT = buff2[counter2]+BIT7;
- if(counter1==8)
- {
- P2OUT&=~BIT1;
- P4OUT = dz1[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[8];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz2[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz3[3];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[7];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz4[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- if((1!=counter1) & (8!=counter1))
- {
- P2OUT&=~BIT1;
- P4OUT = dz7[counter1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz6[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz5[0];
- delay_ms(3000);
- P2OUT&=~BIT1;
- P4OUT = dz2[0];
- delay_ms(1000);
- counter1--;
- temp = counter1;
- counter1++;
- P2OUT&=~BIT1;
- P4OUT = dz7[temp];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz3[3];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[temp];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz4[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- if(counter1==0)
- {
- P2OUT&=~BIT1;
- P4OUT = dz1[1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz7[counter1];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz6[0];
- delay_ms(1000);
- P2OUT&=~BIT1;
- P4OUT = dz5[0];
- delay_ms(3000);
- P2OUT&=~BIT1 ;
- }
- counter1--;
- while((P1IN&BIT3)==0);
- while((P1IN&BIT5)==0);
- P3OUT&=~BIT7;
- }
- if ((P1IN & BIT4) == 0) // 回退
- {
- counter1++;
- counter2++;
- P3OUT = buff2[counter2];
- while((P1IN&BIT4)==0);
- }
- if ((P1IN & BIT5) == 0) // 重復報站
- {
- P2OUT&=~BIT1;
- counter1++;
- counter2++;
- goto pl2;
- }
- if ((P1IN & BIT6) == 0) // 復位
- {
- counter1=9;
- counter2=0;
- P3OUT = buff2[counter2];
- counter2=10;
- while((P1IN&BIT6)==0);
- }
- if ((P1IN & BIT2) == 0) // 正反選擇
- {
- counter3++;
- if((counter3%2)==0)
- { flag = 0;
- P2OUT |= BIT2;
- counter1=0;
- counter2=0;
- }
- if((counter3%2)==1)
- {
- flag = 1;
- P2OUT &= ~BIT2;
- counter1=8;
- counter2=10;
- }
- while((P1IN&BIT2)==0);
- }
- }
- }
- }
- }
- }
復制代碼
|
-
-
proteus上鍵盤掃描.zip
2016-6-22 10:29 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
70.24 KB, 下載次數: 109, 下載積分: 黑幣 -5
仿真源程序,原理圖
評分
-
查看全部評分
|