作品简介:多功能彩灯照亮夜晚多功能装修家具灯光
二、功能介绍:多种彩灯调试,并切有加入了闪烁和呼吸灯
三、硬件介绍:迪文屏,hdmi线,小灯管,sd卡
四、界面设计:file:///C:/Users/27354/AppData/Local/Temp/ksohtml12268/wps1.jpg
五、代码设计: #include "sys.h" #define T0_PERIOD_1MS 0xFF54 void timer0_init() { TMOD &= 0xFC; TMOD |= 0x01; TH0 = (u8)(T0_PERIOD_1MS >> 8); TL0 = (u8)T0_PERIOD_1MS; ET0 = 1; EA = 1; TR0 = 1; } u16 r, g, b, count1, count2, count3,MOD,num,temp; sbit RED = P2 ^ 0; sbit GREEN = P2 ^ 1; sbit BLUE = P2 ^ 2; void io_init() { PORTDRV = 0x02; P2MDOUT |= 0x07; } void RGB(u8 R, u8 G, u8 B) { if (count1 < R) { RED = 1; } else RED = 0; if (count2 < G) { GREEN = 1; } else GREEN = 0; if (count3 < B) { BLUE = 1; } else BLUE = 0; }
void fun_read(u16 *r, u16 *g, u16 *b) { sys_read_vp(0x4100, (u8*)r, 1); sys_read_vp(0x4200, (u8*)g, 1); sys_read_vp(0x4300, (u8*)b, 1); } void fun_write(u16 r, u16 g, u16 b) { sys_write_vp(0x4100, (u8*)&r, 1); sys_write_vp(0x4200, (u8*)&g, 1); sys_write_vp(0x4300, (u8*)&b, 1); }
void init() { sys_init();¯ io_init(); timer0_init(); r = 0; g = 0; b = 0; count1 = 0; count2 = 0; count3 = 0; num = 0; }
void set(u16 a1, u16 a2, u16 a3) { r = a1; g = a2; b = a3; }
void fun(u16 x) { switch (x) { case 1:set(0x0078, 0x003c, 0x0078); break; case 2:set(0x000c, 0x001e, 0x001a); break; case 3:set(0x0066, 0x0066, 0x0066); break; case 4:set(0x0058, 0x0008, 0x0008); break; case 5:set(0x00f0, 0x003c, 0x001e); break; case 6:set(0x003c, 0x001e, 0x00f0); break; case 7:set(0x001e, 0x003c, 0x00f0); break; case 8:set(0x005a, 0x0078, 0x003c); break; case 9:set(0x00b4, 0x0078, 0x003c); break; case 10:set(0x00b4, 0x0078, 0x001e); break; case 11:set(0x003c, 0x0096, 0x0028); break; case 12:set(0x0096, 0x0064, 0x0032); break; case 13:set(0x0032, 0x0064, 0x00fa); break; case 14:set(0x0064, 0x0032, 0x00fa); break; case 15:set(0x00c8, 0x000a, 0x0032); break; case 16:set(0x000a, 0x00c8, 0x0032); break; default:set(0x0006, 0x0006, 0x0006);break; } }
void main(void) { init(); while (1) { sys_read_vp(0x1000, (u8*)&MOD, 1); sys_read_vp(0x2000, (u8*)&num, 1); switch (MOD) { case 1: break; case 3: sys_delay_ms(500); break; case 5: sys_delay_ms(100); break; case 7: fun(num); fun_write(r, g, b); RGB(r,g,b); break; default: break; } fun_read(&r, &g, &b); RGB(r, g, b); } } void timer0_isr() interrupt 1 { TH0 = (u8)(T0_PERIOD_1MS >> 8); TL0 = (u8)T0_PERIOD_1MS;
count1++; count2++; count3++;
if (count1 == 255)count1 = 0; if (count2 == 255)count2 = 0; if (count3 == 255)count3 = 0; }
六、接口连接:p1,p2,p3 end
七、系统实现与测试: file:///C:/Users/27354/AppData/Local/Temp/ksohtml12268/wps2.jpg
|