找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3520|回复: 1
收起左侧

建荣蓝牙CW6685_CW6686原理图、源程序

[复制链接]
ID:628014 发表于 2019-10-22 08:47 | 显示全部楼层 |阅读模式
这个是建荣蓝牙CW6685_CW6686原理图、原程式

编译器用IAR 8051 v7.20H
此版软件已量产

单片机源程序如下:
  1. /*****************************************************************************
  2. * Module    : Main
  3. * File      : main.c
  4. * Author    : Hanny
  5. * Function  : 主函数
  6. *****************************************************************************/
  7. #include "include.h"
  8. #include "task.h"
  9. #include "user_spi.h"
  10. #include "user_fm.h"
  11. #include "user_fft_led.h"

  12. #define MSG_POOL_DEPTH      0x20
  13. u8 msg_pool[MSG_POOL_DEPTH];
  14. void buck_mode_select(void);
  15. extern u8 timer5ms_cnt, timer100ms_cnt, timer1s_cnt;
  16. extern void bt_close(void);
  17. u8 freq_show_update;
  18. u8 ocx_show_cnt;      //用来控制一些控制的显示时间
  19. u8 dac_vdd_hp_flag;

  20. void bt_param_init(void);
  21. bool btdec_load_code(u16 addr, u8 segnum);
  22. void spctl_init(void);
  23. void power_down_enter(void);
  24. void timer_init(void);
  25. /*
  26. #pragma vector = VECTOR_OFFSET(RTCC_INT)
  27. #pragma register_bank=3
  28. __interrupt __near_func void rtc_isr(void)
  29. {
  30.     ISR_ENTER();
  31.     if(IRTCON & BIT(5)){
  32.        //IRTCON &= ~BIT(5);
  33.        printf("isxx!!");
  34.     }

  35.     if(IRTCON & BIT(3)){
  36.        //IRTCON &= ~BIT(3);
  37.        printf("isoo!!");
  38.     }
  39.     ISR_EXIT();
  40. }
  41. */

  42. void flush_dispensable_msg(void)
  43. {
  44.     u8 msg;
  45.     for(u8 i=0; i<MSG_POOL_DEPTH; i++) {
  46.         msg = get_msg();
  47.         if(msg == Q_NOMSG) {
  48.             break;
  49.         } else if(msg >= 0x60 && msg < 0x7e) {    //重要的系统消息留下
  50.             put_msg(msg);
  51.         }
  52.     }
  53. }

  54. #pragma location="RTC_SEG"
  55. void rtc_poweron_set(void)
  56. {
  57. #if SYS_CRY == CRY_32K
  58.     if(irtcc_read_ram8(FIRST_POWERON_FLAG) == 0xAA) //第一次上电
  59.     {
  60.         irtcc_write_ram8(FIRST_POWERON_FLAG, 0x00);
  61.         //printf("p_set\n");
  62.         memset(&t_time, 0, sizeof(t_time));
  63. #if 1
  64.         t_time.year = 15;//15;
  65.         t_time.hour = 8;//8;
  66.         t_time.minute = 0;//8;
  67.         t_time.second = 0;
  68.         set_rtc_time(); //初始化为2015年1月1日8:00   //根据t_time,写RTC时间counter
  69.         irtcc_write_rtc(WRITE_ALM,0);  //闹钟时间清零
  70.         irtcc_write_ram32(NEXT_ALARM, 0);
  71.         user_set_alarm_time(0,0);
  72. #else  //ALARM TEST, 打开这里,15S会会进入闹钟模式
  73.         t_time.year = 0;//15;
  74.         t_time.hour = 0;//8;
  75.         t_time.minute = 1;
  76.         t_time.second = 45;
  77.         set_rtc_time(); //初始化为2015年1月1日8:00   //根据t_time,写RTC时间counter
  78.         irtcc_write_rtc(WRITE_ALM,2*60);  //闹钟时间清零
  79.         irtcc_write_ram32(NEXT_ALARM,2*60);
  80.         user_set_alarm_time(0,2);
  81.   #if ALARM_EN
  82.         user_set_alarm_switch(1);  //打开闹钟开关
  83.   #endif
  84. #endif

  85.     }
  86. #endif
  87. }

  88. #define FIRST_POWER  2 //WRITE_CFG时注意这一位,用于判断是否是第一次上电
  89. #pragma location="RTC_SEG"
  90. void irtcc_init(void)
  91. {
  92.     PCON2 &= ~BIT(3);
  93.     u8 cfg =irtcc_read_cfg(READ_CFG);
  94.     u8 wko = irtcc_read_cfg(READ_WKO);
  95.     if((cfg & BIT(FIRST_POWER)) ){   //用于第一次上电的判断.(PWRCON的BIT7 PD_FLAG读不出来)
  96.         irtcc_write_ram8(FIRST_POWERON_FLAG, 0xAA);
  97.         irtcc_write_rtc(WRITE_ALM,0);  //闹钟时间清零
  98.         irtcc_write_rtc(WRITE_RTC,0);  //时间清零
  99.         //printf("FON\n");
  100.     }else{
  101.         //printf("NF\n");
  102.     }
  103.     //printf("cfg=0x%X\n\n",cfg);
  104.     //printf("wko=0x%X\n\n",wko);
  105.     if(wko & BIT(0)){  //当前是闹钟唤醒
  106.         sys_ctl.alarm_wakeup_flag = true;
  107.         //printf("WK\n");
  108.     }else{
  109.         sys_ctl.alarm_wakeup_flag = false;
  110.         //printf("NWK\n");
  111.     }
  112. #if IRTCC_WKUP_EN
  113.     u8 irtcc_cfg = irtcc_read_cfg(WK_STA_RCMD);
  114.     irtcc_write_cfg(WRITE_WKO,0x41);     //BIT(6) wko pin output enable  BIT(1) WKO pin wakeup enable
  115. #if SYS_CRY == CRY_32K
  116.     irtcc_write_cfg(WRITE_CFG,0x98);
  117. #elif SYS_CRY == CRY_12M
  118.     irtcc_write_cfg(WRITE_CFG,0x58); //32K:0x98  12M:0x58
  119. #endif
  120. #else

  121. #if SYS_CRY == CRY_32K
  122.     irtcc_write_cfg(WRITE_CFG,0x88);  //here  //0x88
  123. #elif SYS_CRY == CRY_12M
  124.     irtcc_write_cfg(WRITE_CFG,0x48); //32K:0x88  12M:0x48
  125.     //irtcc_write_cfg(OSC_DRV_WCMD,0x51);   //12M
  126. #endif
  127. #endif

  128. #if IRTCC_WKUP_EN
  129.     RTC_ALARM_CLR_PEND();        //clear alarm pending
  130.     //RTC_ALARM_INT_EN();        //alarm int enable
  131. #endif
  132. }



  133. #pragma location="INIT_SEG"
  134. void uart_init_hook(void)  //lib中main函数会调用的打印函数
  135. {
  136. #if DEBUG_UART_SEL
  137.     uart_init();
  138.     my_printf_init(uart_putchar);
  139. #else
  140.     my_printf_init((void (__near_func *)(char))dummy_void);
  141. #endif
  142. }

  143. void sys_var_init(void)
  144. {
  145.     memset(&sys_ctl, 0, sizeof(sys_ctl));  //在最前面清零
  146.     task_hid_flag = 0;
  147.     bt_low_scan_flag = 0;
  148. }

  149. void sys_init(void)
  150. {
  151.     PCON1 &= ~(BIT(7) | BIT(6) | BIT(2) | BIT(1) | BIT(0));
  152.     PCON2 &= ~(BIT(6));
  153.     PCON3 &= ~BIT(5);
  154.     PCON1 &= ~BIT(7);
  155.     sys_var_init();
  156. #if SYS_CRY == CRY_32K  //使用外接的32k晶振
  157.     sys_pll_x32k();
  158. #endif
  159.     irtcc_init();
  160. #if IS_LCD_DISPLAY
  161.     LCD_RESET();                //LCD res 防止出现雪花
  162. #endif
  163.     user_io_init();
  164.     scan_init();                            //初始化扫描控制
  165. #if BUCK_MODE_EN
  166.     buck_mode_select();
  167. #else
  168.     if(get_chip_type() == 1){ //CW6686 加大RVDD到最大,改善GFSK,以改善部分芯片通话效果不理想的问题
  169.         PWRCON4 &= ~(BIT(4)|BIT(5));  //set RVDD voltage 00:1.15, 01:1.23, 10:1.28, 11:1.32
  170.         PWRCON4 |= BIT(5);
  171.         PWRCON4 |= BIT(4);
  172.     }
  173. #endif

  174. #if !DEBUG_UART_SEL
  175.     uart_disable();
  176. #endif

  177. #if IS_LEDSEG_DISPLAY
  178.     ledseg_init();
  179.     ledseg_disp(MENU_POWERON);
  180. #endif
  181.     led_mode_on();
  182.     timer_init();
  183.     spctl_init();
  184. #if IS_LCD_DISPLAY
  185.     set_lcd_buf(LCD_FULL_MODE); //设置初始化显存
  186.     disp_language_numget();
  187.     lcd_init(); //lcd显示初始化
  188.     disp_clear();
  189.     disp_draw(RES_POWERON_WELCOME_BMP, 5, 2);
  190.     disp_update();
  191.     LCD_BACKLIGHT_ON();
  192. #endif
  193.     param_init();                           //上电初始化记忆设备
  194.     rtc_poweron_set();
  195. #if FFT_LED_EN
  196.     fft_led_init();
  197. #endif
  198.     msg_init(msg_pool, MSG_POOL_DEPTH);
  199.     device_init();
  200. #if SD_CMD_REUSE_SD_DETECT
  201.     P3PUS0 &= ~BIT(1);
  202. #endif
  203. #if EAR_ADKEY_REUSE
  204.     device_set_delay(DEVICE_EAR,4);  //device_set_delay可以更改设备检测的延时时间
  205. #endif

  206. #if HARD_IR_EN
  207.     ir_hardware_init();
  208. #elif SOFT_IR_EN
  209.     ir_timer2_init();
  210. #endif
  211.     sys_ctl.spk_mute = 1;
  212.     timer5ms_cnt = timer100ms_cnt = timer1s_cnt = 0;
  213.     timer1_hook_enable();                   //初始化完毕,开启定时器扩展,以便各项检测等。
  214.     dac_init(DAC_INIT_MODE);
  215. #if DAC_MIX_OUT_EN
  216.     dac_left_right_mix_out();
  217. #endif
  218. #if VCMBUF_EN
  219.     uart_disable();                         //关闭串口的使用
  220.     dac_vcmbuf_en();                        //使用VCMBUF
  221. #endif
  222.     flush_msg();
  223.     set_sys_clk(SYS_48M);                   //初始化完毕,设置时钟

  224. #if WARNING_POWER_ON
  225.     if (!sys_ctl.mute_flag) {
  226.         sys_unmute();
  227.     }
  228.     dac_enable();
  229.     mp3_res_play_wait(RES_MP3_START);       //播放开机提示音.中调用的EVENT有可能改变work_sta值
  230. #endif

  231. #if TASK_BT_EN
  232. #if BT_ALL_TASK
  233.     user_bt_init();
  234.     //开始回连
  235.     bt_connect();
  236. #else
  237.     user_bt_init();
  238.     bt_close();
  239. #endif
  240. #endif

  241. #if ALARM_EN
  242.     if (task_alarm_check()) {
  243.         task_alarm_clear();
  244.     } else {
  245.         if(!sys_ctl.alarm_wakeup_flag){
  246.             task_alarm_set();               //设置闹钟
  247.         }
  248.     }
  249.     next_alarm = irtcc_read_rtc(READ_ALM);
  250. #endif

  251. #if IS_LCD_DISPLAY
  252.     sys_ctl.poweroffcnt = 0xffff;   // 初始化时禁止启动定时关机功能
  253.     reset_backlight();              // 背光时间要重新设置,不然就初值为0
  254. #endif
  255. }

  256. //软开关开机键检测
  257. void soft_power_check(void)
  258. {
  259.     u16 cnt;
  260.     for (cnt = 500; cnt!=0; cnt--) {
  261.         if (!SOFT_POWER_CHK_IS_ON()) {
  262.             //printf("power_off\n");
  263.             WDTCON = 0;
  264.             SOFT_POWER_CTL_OFF();
  265.             while (1);
  266.         }
  267.         delay(2800);
  268.     }
  269.     //printf("power_on\n");
  270.     SOFT_POWER_CTL_ON();
  271. }

  272. #pragma constseg="INIT_CONST"
  273. IAR_CONST char str_showsid[] = "SID:%lu\n";
  274. IAR_CONST char str_start[] = "\nStart\n";
  275. #pragma constseg=default

  276. #pragma location="INIT_SEG"
  277. void main(void)
  278. {
  279.     IE0 = 0;                //关闭所有中断
  280.     IE1 = 0;
  281.     DPCON = 0;
  282.     IE_EA = 1;
  283.     sys_init();
  284.     run_task();
  285.     while (1);
  286. }
复制代码

所有资料51hei提供下载:
APP.7z (3.26 MB, 下载次数: 54)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:520235 发表于 2024-8-3 13:40 | 显示全部楼层
感谢分享,下载来看看学习。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表