分享一个HC8F003 无线充电方案
包括源代码
硬件原理图
BOM表
版本说明:
1、Holychip_WirelessCharger_Library functionV1.0.0.0 初版
2、Holychip_WirelessCharger_Library functionV1.0.0.1 修改基本参数
电路原理图如下:
单片机源程序如下:
- /**
- * @Examle Version V1.0.0.1
- * @Demo Version V1.0.0.0
- * @Date 2018.03.01
- * ************************************************************************************
- * 客户服务
- * 感谢您使用我们的单片机,若发现错误或对函数的使用存在疑问。
- **/
- #define ALLOCATE_EXTERN
- #include "Include.h"
- #define Code1_Pin P1_1
- #define Code2_Pin P2_4
- /***************************************************************************************
- * @函数名 int main()
- * @说明 主函数
- * @参数 无
- * @返回值 无
- * @注
- ***************************************************************************************/
- int main()
- {
- SystemInit(); //系统初始化
- DispalyDateInit(); //显示 数据初始化
- QI_Init();
- EA = 1; //打开总中断
- while(1)
- {
- Systerm();
- }
- return 0;
- }
- /***************************************************************************************
- * @说明 T0中断服务函数
- * @参数 无
- * @返回值 无
- * @注 62.5us 中断处理一次
- ***************************************************************************************/
- void TIMER0_Rpt(void) interrupt TIMER0_VECTOR
- {
- signal2 = Code1_Pin; //Sdata 4 62.5us 采集Code值 解码
- signal1 = Code2_Pin; //Sdata 6 62.5us 采集Code值 解码
- Interrupt();
- }
复制代码- #include "Include.h"
- extern unsigned char code code_FREQ_INIT = FREQ_INIT_df;
- extern unsigned int code code_LOAD_LEVEL_TIME = LOAD_LEVEL_TIME_df;
- extern unsigned int code code_Fod_sensitivity = Fod_sensitivity_df;
- unsigned int gui_Cycle = 0; //周期时间
- unsigned int gui_DutyRatio = 0; //占空比时间
- unsigned char guc_DeadTime = 3; //死区时间设置
- /***************************************************************************************
- * @说明 系统初始化
- * @参数 无
- * @返回值 无
- * @注 无
- ***************************************************************************************/
- void SystemInit(void)
- {
- WDTCCR = 0x00; //关闭看门狗
- while((CLKCON&0x20)!=0x20); //等待内部高频RC起振
- CLKSWR = 0x51; //选择内部高频时钟为主时钟,内部高频RC2分频,Fosc=16MHz
- while((CLKSWR&0xC0)!=0x40); //等待内部高频切换完成
- CLKDIV = 0x01; //Fosc1分频得到Fcpu,Fcpu=16MHz
-
- P0M0 = 0x83; //P01 Test P00 None
- P0M1 = 0x38; //P03 Rst P02 Test
- P0M2 = 0x33; //P05 I P04 Temp
- P0M3 = 0x33; //P07 Coil P06 2.5V
- P1M0 = 0x08; //P11 Code1 P10 Blue
- P2M0 = 0x38; //P21 SWIM P20 BEEP
- P2M1 = 0x88; //P23 PWML1 P22 PWMH2
- P2M2 = 0x80; //P25 PWML2 P24 Code2
- P2M3 = 0x88; //P27 RED P26 PWMH1
-
- PWM1_MAP = 0x26; //PWM1映射P26口
- PWM11_MAP = 0x25; //PWM11映射P23口
- PWM2_MAP = 0x23; //PWM2映射P22口
- PWM21_MAP = 0x22; //PWM21映射P25口
- PWM1C = 0x00; //PWM1和PWM11均为高有效,时钟1分频
- PWM2C = 0x00; //PWM2和PWM21均为高有效,时钟1分频
- PWM1EN = 0x01; //打开PWM1但是PWM1和PWM11不输出
-
- PWM2EN = 0x01; //打开PWM2但是PWM2和PWM21不输出
- Delay_Ms(1); //延时一段时间滤掉前期不稳定波形,延时时间根据实际设定,延时时间大于2个PWM周期即可
- PWM1EN |= 0x06;
- PWM2EN |= 0x06; //使能PWM输出
- TCON1 = 0x00; //Tx0定时器时钟为Fosc
- TMOD = 0x00; //16位重装载定时器/计数器
- TH0 = 0xFF;
- TL0 = 0xAD; //T0定时时间62us
- IE |= 0x02; //打开T0中断
- TCON |= 0x10; //使能T0
-
- ADCC0 = 0x80; //打开ADC转换电源
- ADCC2 = 0xCD; //转换结果10位数据,数据右对齐,ADC时钟16分频
- }
复制代码
代码不完整:
Holychip_WirelessCharger_Library functionV1.0.0.1.rar
(165.1 KB, 下载次数: 321)
|