32路搖搖棒制作。
0.png (242.08 KB, 下載次數: 93)
下載附件
2016-11-13 15:09 上傳
0.png (74.86 KB, 下載次數: 98)
下載附件
2016-11-13 15:10 上傳
所有制作資料打包下載:
32燈搖搖棒資料.rar
(7.83 MB, 下載次數: 143)
2015-7-31 10:54 上傳
點擊文件名下載附件
32路搖搖棒 下載積分: 黑幣 -5
以下是部分源程序預覽:
- /****************************************************************************************
- /*硬件制作:07電氣工程 張國榮
- /*軟件調試:07電氣工程 付春平
- /*描 述: 搖搖棒程序,通過滾珠開關檢測周期,搖動時間自適應,圖像始終保持在中間。開機后每搖晃10次切換下一組字模
- /* 按了一下按鍵后變成了手動切換,直到回到第一組字的時候再自動切換
- 如有問可直接加我QQ:77554971
- 技術交流群:120069344
- 套件出售
- 詳細制作在里面了!
- 最后祝各位制作成功!學習進步!
- /*****************************************************************************************/
- #include <STC11F60XE.h>
- /*********外部接口定義**********/
- #define uchar unsigned char
- #define uint unsigned int //宏定義
- #define out P1 //數據輸出端口
- sbit led1=P3^0; //第1組LED
- sbit led2=P3^1; //第2組LED
- sbit led3=P3^3; //第3組LED
- sbit led4=P3^4; //第4組LED
- sbit key1=P3^5; //按鍵輸入
- sbit p3_2=P3^2;
- uchar KY,num; //KY作用在后面說明
- uchar BUFF; //緩存
- /*********全局變量定義**********/
- unsigned long int TimeCount=0;
- unsigned int DelayN=80, //延時臨時計數
- DelayTime=80; //每次延時的周期個數
- unsigned char key,keyy;
- /**********************************************/
- void delay(unsigned char n);
- void DelayMs(void);
- /*******************************************/
- unsigned char code text0[]={
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xB7,0xBB,0xB7,0xBB,0xB3,0xBB,0xB4,0xBB,0xB5,0xBB,0xB7,0xBB,0xB7,0xBB,0xB7,0xBB,0x07,0x00,0xFF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F,0x00,0x00,0xE0,0x1F,0x00,0x00,0xE0,0x3F,0x00,0x00,0xC0,0x3F,0x00,0x00,0x80,0x1F,0x00,0x00,0xC0,
- 0x0F,0x00,0x00,0xE0,0x07,0x00,0x00,0xF0,0x03,0x00,0x00,0xF8,0x03,0x00,0x00,0xFC,0x03,0x00,0x00,0xFE,0x03,0x00,0x00,0xFF,0x07,0x00,0x80,0xFF,0x0F,0x00,0xC0,0xFF,
- 0x1F,0x00,0xE0,0xFF,0x3F,0x00,0xE0,0xFF,0xFF,0x00,0xF8,0xFF,0xFF,0x01,0xFC,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x07,0x00,0x00,0xE0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xC7,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,
- 0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xC7,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,/*"未命名文件",0*/
- };
- /***********n(us)延時子程序***************/
- void DelayUs(uint N)
- {
- uint x;
- for(x=0; x<=N;x++);
- }
- /******************************************/
- void main()
- {
- AUXR=0x80;
- CLK_DIV=1;
- EX0=1; //開放外部中斷0
- IT0=1; //中斷0為邊沿觸發方式
- IP=0x02; //設置中斷優先級
- TMOD=0x02; //定時器0方式2,8位重裝載
- TH0=0x80; //設定定時器初值
- TL0=0x80;
- KY=0;
- EA=1; //開放中斷
- ET0=1; //開放定時器0中斷
- TR0=1; //啟動定時器0,開始計時*/
- key=0; //初始化顯示第一組文字
- keyy=0;
- P1M0=0x55; //0101 0101 /P1.0 P1 .2 P1.4 P1.6推挽輸出
- P1M1=0xAA;
- while(1){//等待中斷
-
- if(key1==0){ //有鍵按下
- DelayUs(50);
- if(key1==0){
- key++; //更換下一幅圖片
- if(key>2) key=0; //圖片循環顯示 根據顯示的組數來定義 這里有9組 所以就要keyy>9
- while(key1==0); //等待按鍵釋放
- }
- }
- if(num>10) //每中斷10次切換
- {
- keyy++;
- num=0;
- }
- if(keyy>2)keyy=0; //圖片循環顯示 根據顯示的組數來定義 這里有9組 所以就要keyy>9
- }
- }
-
- /*********文字顯示子程序**********/
- void display_word(unsigned char code *text)
- {
- unsigned char i,j=2; //j為圖片起始位置 3 為第3個開始是圖片 如果要顯示高時32的大字 也屬于圖片格式
- DelayUs(6400);
-
- for(i=0;i<64;i++)
- {
-
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B;
- if((key>=j)||(keyy>=j))
- BUFF=(*(text+i*4+3));
- else
- BUFF=(*(text+128+i*2+1));
- led4=0;
- P1=~BUFF>>1;
- P3M0=0x10; //0001 0000 //P3.4推挽輸出 P3 .0 P3.3 P3.1輸入高阻
- P3M1=0x0B; //0000 1011
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001 1011
- led4=1;
- P1=BUFF; //01010101 1357
- P3M0=0x10; //0001 0000 //P3.4推挽輸出 P3 .0 P3.3 P3.1輸入高阻
- P3M1=0x0B; //0000 1011
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001 1011
- if((key>=j)||(keyy>=j))
- BUFF=(*(text+i*4+2));
- else
- BUFF=(*(text+128+i*2));
- led3=0;
- P1=~BUFF>>1;
- P3M0=0x08; //0000 1000 //P3.3推挽輸出 P3 .0 P3.1 P3.4輸入高阻
- P3M1=0x13; //0001 0011
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001 1011
- led3=1;
- P1=BUFF; //01010101 1357
- P3M0=0x08; //0000 1000 //P3.3推挽輸出 P3 .0 P3.1 P3.4輸入高阻
- P3M1=0x13; //0001 0011
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B;
- if((key>=j)||(keyy>=j))
- BUFF=(*(text+i*4+1));
- else
- BUFF=(*(text+i*2+1));
- led2=0;
- P1=~BUFF>>1;
- P3M0=0x02; //0000 0010 //P3.1推挽輸出 P3 .0 P3.3 P3.4輸入高阻
- P3M1=0x19; //0001 1001
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001 1011
- led2=1;
- P1=BUFF; //01010101 1357
- P3M0=0x02; //0000 0010 //P3.1推挽輸出 P3 .0 P3.3 P3.4輸入高阻
- P3M1=0x19; //0001 1001
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001
- if((key>=j)||(keyy>=j))
- BUFF=(*(text+i*4));
- else
- BUFF=(*(text+i*2));
- led1=0;
- P1=~BUFF>>1;
- P3M0=0x01; //0000 0001 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1A; //0001 1010
- delay(1);
- P3M0=0x00; //0000 0000 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1B; //0001 1011
- led1=1;
- P1=BUFF; //01010101 1357
- P3M0=0x01; //0000 0001 //P3.0推挽輸出 P3 .1 P3.3 P3.4輸入高阻
- P3M1=0x1A; //0001 1010
- delay(1);
- } }
- /*********顯示內容選擇子程序**********/
- void display(unsigned char t)
- { keyy=0;
- switch (t){ //通過按鍵選擇顯示內容
- case 0: {display_word(text0);}break;
- case 1: {display_word(text1);}break;
- case 2: {display_word(text2);}break;
- // case 3: {display_word(text3);}break;
- // case 4: {display_word(text4);}break;
- // case 5: {display_word(text5);}break;
- // case 6: {display_word(text6);}break;
- // case 7: {display_word(text7);}break;
- // case 8: {display_word(text8);}break;
- // case 9: {display_word(text9);}break;
- // case 10:{display_word(text10);}break;
- //default:{display_word(text1);}
-
-
- }}
- /*****************************************/
- void display1(unsigned char y)
- {
- switch (y){ //通過按鍵選擇顯示內容
- case 0: {display_word(text0);}break;
- case 1: {display_word(text1);}break;
- case 2: {display_word(text2);}break;
- // case 3: {display_word(text3);}break;
- // case 4: {display_word(text4);}break;
- // case 5: {display_word(text5);}break;
- // case 6: {display_word(text6);}break;
- // case 7: {display_word(text7);}break;
- // case 8: {display_word(text8);}break;
- // case 9: {display_word(text9);}break;
- // case 10:{display_word(text10);}break;
- }
- }
- /***************************************/
- /*********延時子程序**********/
- void delay(unsigned char n)
- {
- for(;n>0;n--){
- DelayN=DelayTime;
- while (DelayN);
- }
- }
- /*********中斷子程序**********/
- void int0() interrupt 0 //使用外部中斷0
- {
- KY=~KY;
- if(KY==0)
- {
- DelayTime=TimeCount/1580;
- TimeCount=0; //延時周期計數清零
- if(key==0)
- {
- num++;
- display1(keyy); //根據按鍵選擇循環顯示文字
- }
- else
- {
- display(key); //根據按鍵選擇循環顯示文字
- }
- }
- }
- void timer0() interrupt 1 //定時器0中斷子程序
- {
- TimeCount++;
- if (DelayN!=0)
- DelayN--;
- }
復制代碼
|