|
|
型号: DMT12800K070_A2WTC
- //用户数据库要保存数据的位置
- //[0x00] 亮度
- //[0x10] 音量
- //工程中设置的数据变量
- //[0x3300] 亮度
- //[0x3400] 音量
- //[0xFFF0] 临时地址,交换数据用
- void page(unsigned char page);
- void flash(int mod,long addr_flash,int addr, int len);
- void Backlight_brightness(unsigned char normal, unsigned char Standby);
- int main()
- {
- char cur_brightness[4] = {0};
- char last_brightness[4] = {0};
- char cur_volume[4] = {0};
- char last_volume[4] = {0};
-
- int *p_cur_brightness = cur_brightness;
- int *p_last_brightness = last_brightness;
- int *p_cur_volume = cur_volume;
- int *p_last_volume = last_volume;
- Backlight_brightness(0, 0);
- // flash(0x5A, 0x00, 0xFFF0, 2); //读取用户数据库中的[亮度],保存到临时地址处
- // read_dgus_vp(0xFFF0, last_brightness, 2);
- // if (*p_last_brightness == 0) //判断flash内是不是0
- // {
- // //首次烧录程序,nor flash内还没有数据,直接写入默认值(5档[亮度])
- // *p_last_brightness = 5;
- // write_dgus_vp(0xFFF0, last_brightness, 2);
- // flash(0xA5, 0x00, 0xFFF0, 2);
- // }
- // else
- // {
- // //如果不是首次烧录程序,就把数据读取出来给显示[亮度]档位处
- // write_dgus_vp(0x3300, last_brightness, 2); //将[亮度]写入档位处[0x3300]
- // (*p_last_brightness) = (0x10 * (*p_last_brightness)) + 0x16;
- // //write_dgus_vp(0x0082, last_brightness, 2); //将[亮度]换算后写入亮度寄存器[0x0082]
- // Backlight_brightness(0, 50);
- // }
-
- // flash(0x5A, 0x10, 0xFFF0, 2);//read_dgus_vp(0x10, last_volume, 4); //读取用户数据库中的音量,保存到临时地址处
- // read_dgus_vp(0xFFF0, last_volume, 2);
- // if (*p_last_volume == 0)//判断flash内是不是0
- // {
- // //首次烧录程序,nor flash内还没有数据,直接写入默认值(3档音量)
- // *p_last_volume = 3;
- // write_dgus_vp(0xFFF0, last_volume, 2);
- // flash(0xA5, 0x10, 0xFFF0, 2);
- // }
- // else
- // {
- // //如果不是首次烧录程序,就把数据读取出来给显示[音量]档位处
- // write_dgus_vp(0x3300, last_volume, 2); //将亮度写入[音量]档位处[0x3300]
- // switch (*p_last_volume)
- // {
- // case 1: *p_last_volume = 0x10; break;
- // case 2: *p_last_volume = 0x20; break;
- // case 3: *p_last_volume = 0x30; break;
- // case 4: *p_last_volume = 0x40; break;
- // case 5: *p_last_volume = 0xFF; break;
- // default:break;
- // }
- // write_dgus_vp(0x00A0, last_volume, 2); //将亮度换算后写入[音量]寄存器[0x00A0]
- // }
- page(3);
-
- while (1)
- {
- // read_dgus_vp(0x3300, cur_brightness, 2); //读取实时亮度
- // if (*p_cur_brightness != *p_last_brightness)
- // {
- // *p_last_brightness = *p_cur_brightness; //更新亮度值
- // write_dgus_vp(0xFFF0, last_brightness, 2);
- // flash(0xA5, 0x00, 0xFFF0, 2); //将数据写入用户数据库
- // }
-
- // read_dgus_vp(0x3400, cur_volume, 2); //读取实时音量
- // if (*p_cur_volume != *p_last_volume)
- // {
- // *p_last_volume = *p_cur_volume; //更新音量值
- // write_dgus_vp(0xFFF0, last_volume, 2);
- // flash(0xA5, 0x10, 0xFFF0, 2); //将数据写入用户数据库
- // }
- }
-
- return 0;
- }
- void delayms(char cnt)
- {
- int i = 0, j = 0;
-
- for(i = 0; i < cnt; i++)
- for (j = 0; j < 1000; j++);
- }
- // 读写FLASH操作
- void flash(int mod,long addr_flash,int addr, int len)
- {
- /*
- 0x08 NOR_FLASH_RW_CMD 4
- D7:操作模式 0x5A=读 0xA5=写,CPU 操作完清零。
- D6:4:片内 Nor Flash 数据库首地址,必须是偶数,0x000000-0x02:7FFE,160KWords。
- D3:2:数据变量空间首地址,必须是偶数。
- D1:0:读写字长度,必须是偶数。
- */
- char rw_flash_cmd[8] = {0}; //数据库读操作
-
- rw_flash_cmd[0] = mod;
- rw_flash_cmd[1] = (unsigned char)(addr_flash >> 16);
- rw_flash_cmd[2] = (unsigned char)(addr_flash >> 8);
- rw_flash_cmd[3] = (unsigned char)(addr_flash & 0xFE);
- rw_flash_cmd[4] = (unsigned char)(addr >> 8);
- rw_flash_cmd[5] = (unsigned char)(addr & 0xFE);
- rw_flash_cmd[6] = (unsigned char)(len >> 8);
- rw_flash_cmd[7] = (unsigned char)(len & 0xFE);
-
- //send_data_com(COM_PORT,rw_flash_cmd,8); // debug
- write_dgus_vp(0x08, rw_flash_cmd, 4); //启动读Flash
- //等待数据读取OK
- while(1)
- {
- delayms(20);
- read_dgus_vp(0x0008,rw_flash_cmd,1);
- if(rw_flash_cmd[0]==0x00)
- break;
- }
- }
- // 切换页面
- void page(unsigned char page)
- {
- /*
- 0x84 PIC_Set 2
- D3:0x5A 表示启动一次页面处理,CPU 处理完清零。
- D2:处理模式。
- 0x01=页面切换(把图片存储区指定的图片显示到当前背景页面)。
- 0x02=不支持。
- D1:D0:图片 ID。
- */
- char cmd[4]={0x5a,0x01,0x00,0x00};
- cmd[3] = page; // 页面编号
- write_dgus_vp(0x0084,cmd,2);
- }
- // 调节背光亮度
- void Backlight_brightness(unsigned char normal, unsigned char Standby)
- {
- /*
- LED_Config 2
- 触摸屏背光待机设置:
- D3=开启亮度,0x00-0x64;背光待机控制关闭时,D3 为软件亮度调节接口。
- D2=关闭亮度 0x00-0x64; D1:0=开启时间/5mS 。
- */
- char cmd[4]={0x64,0x64,0x00,0x00};
- cmd[3] = normal; // 非待机时亮度
- cmd[2] = Standby;
- write_dgus_vp(0x0082,cmd,2);
- }
- void Time0_IRQHandler(void)
- {
- }
- void Time1_IRQHandler(void)
- {
- }
- void Time2_IRQHandler(void)
- {
- }
复制代码 现在使用上述代码无法调节屏幕亮度, 按理说0应该是最暗的, 但是屏幕依旧很亮.
请问是哪里的问题呢?
|
|