|
麻煩各位大神幫我看看
stc-isp發布的項目程序后刷機進單片機的16進制不對, 要發送的0x0E, 0x05, 0x03, 0x05, 0x09, 0x00, 0x03, 0x00, 0x03, 0x5A 0x0E, 0x00, 0x05, 0x00, 0x00, 0x01, 0x01, 0x00, 0x02, 0x5A
單片機源程序如下:
- //本示例在Keil開發環境下請選擇Intel的8058芯片型號進行編譯
- //若無特別說明,工作頻率一般為22118400Hz,串口波特率使用定時器2,波特率115200
- #include "STC15W.h"
- #include "intrins.h"
- typedef unsigned int U16;
- typedef unsigned char U8;
- //-----------------------------------------------
- #define FOSC 22118400L//30000000L//22118400L
- /*
- FOSC T 次數 重載值
- 22118400 12 1000 63692.8
- 22118400 12 100 47104
- 22118400 1 1000 43417.6
- 22118400 1 100 -155648
- 22118400 1 400 10240
- 22118400 1 500 21299.2
- 22118400 1 3000 58163.2
- 22118400 1 5000 61112.32
- 22118400 1 6000 61849.6
- */
- #define T1MS_12T (65536-FOSC/12/1000) //12T模式
- #define T1MS_1T (65536-FOSC/1000) //1T模式
- #define T10MS_12T (65536-FOSC/12/100) //1T模式
- #define T2MS_1T (65536-FOSC/500) //1T模式
- U8 gucTask10msFlg = 0;
- U8 gucTask10msCount = 0;
- U8 gucTask1000msFlg = 0;
- U16 gucTask1000msCount = 0;
- #define KEY P32
- #define LED P37
- /* Timer0 interrupt routine */
- void tm0_isr() interrupt 1
- {
- TL0 = T1MS_1T; //初始化計時值
- TH0 = T1MS_1T >> 8;
- gucTask10msCount++;
- if(gucTask10msCount >= 10)
- {
- gucTask10msCount = 0;
- gucTask10msFlg = 1;
- }
- gucTask1000msCount++;
- if(gucTask1000msCount >= 1000)
- {
- gucTask1000msCount = 0;
- gucTask1000msFlg = 1;
- }
- }
- #define DEBUG
- #ifdef DEBUG
- //#define BRT (65536 - FOSC / 115200 / 4)
- #define BRT (65536 - FOSC / 9600 / 4)
- bit busy;
- U8 digits[17] = "0123456789ABCDEF";
- void UartIsr() interrupt 4
- {
- U8 u8Data = 0;
- if (TI)
- {
- TI = 0;
- busy = 0;
- }
- if (RI)
- {
- RI = 0;
- u8Data = SBUF;
- }
- }
- void UartInit()
- {
- #if 1
- SCON |= 0x50;
- T2L = BRT;
- T2H = BRT >> 8;
- AUXR |= 0x15;
- busy = 0;
- #else
- SCON = 0x50;
- TMOD = 0x00;
- TL1 = BRT;
- TH1 = BRT >> 8;
- TR1 = 1;
- AUXR = 0x40;
- busy = 0;
- #endif
- }
- void UartSend(char dat)
- {
- while (busy);
- busy = 1;
- SBUF = dat;
- }
- void UartSendStr(char *p)
- {
- while (*p)
- {
- UartSend(*p++);
- }
- }
- void PutHEX(U8 c)
- {
- UartSend(digits[(c>>4)&0x0f]);
- UartSend(digits[c&0x0f]);
- }
- #endif
- //-----------------------------------------------
- #define N_KEY 0
- #define S_KEY_DOWN 1
- #define D_KEY 0x20//
- #define L_KEY_DOWN 0x40//
- #define L_KEY_UP 0x80//
- #define KEY_VALUE 0x01
- #define KEY_STATE_0 0
- #define KEY_STATE_1 1
- #define KEY_STATE_2 2
- #define KEY_STATE_3 3
- #define RESET 0
- #define SET 1
- U8 KEY_LOCK1(void)
- {
- static U8 ucKeyState = KEY_STATE_0;
- static U8 ucKeyTime = 0;
- U8 ucKeyPress;
- U8 ucKeyValue = N_KEY;
-
- if(KEY == RESET)
- {
- ucKeyPress = 0;
- }
- else
- {
- ucKeyPress = 1;
- }
-
- switch (ucKeyState)
- {
- case KEY_STATE_0:
- if (!ucKeyPress)
- {
- ucKeyState = KEY_STATE_1;
- }
- break;
- case KEY_STATE_1:
- if (!ucKeyPress)
- {
- ucKeyTime = 0;
- ucKeyState = KEY_STATE_2;
- }
- else
- {
- ucKeyState = KEY_STATE_0;
- }
- break;
- case KEY_STATE_2:
- if(ucKeyPress)
- {
- //ucKeyValue = KEY_VALUE_11;
- ucKeyState = KEY_STATE_0;
- }
- else if (++ucKeyTime >= 2)
- {
- ucKeyValue = KEY_VALUE;//ucKeyValue = KEY_VALUE_11|L_KEY_DOWN;
- ucKeyState = KEY_STATE_3;//ucKeyState = KEY_STATE_3;
- }
- break;
- case KEY_STATE_3:
- if (ucKeyPress)
- {
- //ucKeyValue = KEY_VALUE_11|L_KEY_UP;
- ucKeyTime = 0;
- ucKeyState = KEY_STATE_0;
- }
- break;
- }
-
- return ucKeyValue;
- }
- U8 KeyStatus1Tab[10] = {0x0E, 0x05, 0x03, 0x05, 0x09, 0x00, 0x03, 0x00, 0x03, 0x5A};
- U8 KeyStatus2Tab[10] = {0x0E, 0x00, 0x05, 0x00, 0x00, 0x01, 0x01, 0x00, 0x02, 0x5A};
- U8 KeyStatus = 0;
- /* main program */
- void main()
- {
- U8 i = 0;
- U8 KeyValue = N_KEY;
- P0M0 = 0x00;
- P0M1 = 0x00;
- P1M0 = 0x00;
- P1M1 = 0x00;
- P2M0 = 0x00;
- P2M1 = 0x00;
- P3M0 = 0x00;
- P3M1 = 0x00;
- P4M0 = 0x00;
- P4M1 = 0x00;
- P5M0 = 0x00;
- P5M1 = 0x00;
- P6M0 = 0x00;
- P6M1 = 0x00;
- P7M0 = 0x00;
- P7M1 = 0x00;
- AUXR |= 0x84; //定時器0為1T模式
- //AUXR &= 0x7f; //定時器0為12T模式
- TMOD = 0x00; //設置定時器為模式0(16位n自動重裝載)
- TL0 = T2MS_1T; //初始化計時值
- TH0 = T2MS_1T >> 8;
- TR0 = 1; //定時器0開始計時
- ET0 = 1; //使能定時器0中斷
- #ifdef DEBUG
- UartInit();
- EA = 1;
- ES = 1;
- //UartSendStr("\r\n = = = = = = = = = = Date: 2021/05/03= = = = == = = = = ");
- //UartSendStr("\r\n This Version is Support xx");
- //PutHEX(0);
- #else
- EA = 1;
- #endif
- while (1)
- {
- if(gucTask10msFlg)//10ms掃描一次按鍵
- {
- gucTask10msFlg = 0;
- KeyValue = KEY_LOCK1();//按鍵掃描
- if(KeyValue == KEY_VALUE)//獲取到按鍵按下
- {
- //UartSendStr("\r\n KEY DOWN");
- if(KeyStatus == 0)//發送鍵值1
- {
- for(i = 0; i < 10; i++)
- {
- UartSend(KeyStatus1Tab[i]);
- }
- KeyStatus = 1;
- }
- else //發送鍵值2
- {
- for(i = 0; i < 10; i++)
- {
- UartSend(KeyStatus2Tab[i]);
- }
- KeyStatus = 0;
- }
- }
- }
- if(gucTask1000msFlg)//1000ms輪詢一次
- {
- gucTask1000msFlg = 0;
- }
- }
- }
復制代碼
|
|