芯片复制C8051F330单片机的无线键盘程序
芯片复制单片机源程序如下:
- //-----------------------------------------------------------------------------
- // Includes
- //-----------------------------------------------------------------------------
- #include <c8051f330.h> // SFR declarations
- #include <stdio.h>
- #include "mytype.h"
- #include "config.h"
- static uint16 idle_timeout_time=300;//无按键按下超时,5min
- static uint16 idle_timeout=0;//无按键按下超时
- static uint8 reconn_flag=0;//重新连接标志
- static uint8 poweroff_flag=0;//关机标志
- static uint8 bat_val=0;//电池电压
- static uint8 adc_flag=0;//电池电压测试标志,10min
- static uint16 adc_timeout=0;//电压测试时间
- uint8 code batt[16]= {0x27,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x05,0x04,0x17,0x10,0x0C,0x11}; //0~9,bat,min
- #define vcc_on 1
- #define vcc_off 0
- #define bl_on 0
- #define bl_off 1
- //-----------------------------------------------------------------------------
- // Global CONSTANTS
- //-----------------------------------------------------------------------------
- #define SYSTEMCLOCK 6125000 // SYSCLK frequency in Hz
- #define BAUDRATE 57600 // Baud rate of UART in bps
- #define TIMER_PRESCALER 48 // Based on Timer CKCON settings
- // There are SYSTEMCLOCK/TIMER_PRESCALER timer ticks per second, so
- // SYSCLK/TIMER_PRESCALER/1000 timer ticks per millisecond.
- #define TIMER_TICKS_PER_MS SYSTEMCLOCK/TIMER_PRESCALER/1000
- // Note: TIMER_TICKS_PER_MS should not exceed 255 (0xFF) for the 8-bit timer
- #define AUX1 TIMER_TICKS_PER_MS
- #define AUX2 -AUX1
- #define TIMER0_RELOAD_HIGH AUX2 // Reload value for Timer0 high byte
- //-----------------------------------------------------------------------------
- // Function PROTOTYPES
- //-----------------------------------------------------------------------------
- void ADC0_Init(void);
- void SYSCLK_Init (void);
- void UART0_Init (void);
- void PORT_Init (void);
- void Timer0_Init (void);
- void KEY_VAL(uint8 tmp);
- void delay_ms(uint16 ms);
- //-----------------------------------------------------------------------------
- // Global Variables
- //-----------------------------------------------------------------------------
- static uint8 tx_buf[12]= {0x0C,0x00,0xA1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //HID发送缓冲区
- static uint8 tx_count;//发送字节数,实际发送12个字节
- uint8 fn_flag;//Fn键按下状态
- #define FnDown 0x00
- #define FnUp 0x01
- //key
- #define LCtrl 0x14
- #define LShift 0x12
- #define LAlt 0x10
- #define LGui 0x07
- //#define RCtrl 0x??
- #define RShift 0x59
- #define RAlt 0x13
- //#define RGui 0x??
- #define Fn 0x02
- //fn_key,用于测试。实际使用时查表
- #define Home 0x5E
- #define End 0x2F
- #define PgUp 0x28
- #define PgDown 0x60
- #define Esc 0x0E
- #define F1 0x16
- #define F3 0x26
- //uart缓冲区使用变量
- #define UART_BUFFERSIZE 32
- uint8 UART_Buffer[UART_BUFFERSIZE];
- uint8 UART_Buffer_Size = 0;
- uint8 UART_Input_First = 0;
- uint8 UART_Output_First = 0;
- uint8 TX_Ready =1;
- static uint8 Byte;

芯片解密