| 
 
| 本帖最后由 followme001 于 2014-9-14 20:28 编辑 
 不知道大家有没有用过LED方面的驱动IC,我在写一款LED驱动IC(HD5056)的程序时遇到一个问题,发现时序比较难做到准确,不知道有什么好的办法,特来论坛求教,谢谢指点。以下是我的程序(这个程序是为了练习版主的数据驱动程序思想搞的,还没做到分离那一步:P)
 
 #include "STC12C5608AD.h"
 #include <intrins.h>
 
 sbit DAT = P1^3;
 
 typedef unsigned char uint8;
 typedef unsigned int  uint16;
 
 void reset(void)
 {
 uint8 i;
 DAT = 0;
 
 for (i = 0; i < 255; i++)  //76us
 {
 ;
 }
 }
 
 void send_data(uint8 r, uint8 g, uint8 b)
 {
 uint8 i;
 
 for (i = 8; i > 0; i--)
 {
 if ((r & 0x80) != 0)      //"1"
 {
 DAT = 1;
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();  //860ns
 DAT = 0;  //890ns
 }
 else                                          //"0"
 {
 DAT = 1;
 _nop_();
 _nop_();  //270ns
 DAT = 0;
 _nop_();
 _nop_();  //850ns
 }
 
 r <<= 1;
 }
 
 for (i = 8; i > 0; i--)
 {
 if ((g & 0x80) != 0)
 {
 DAT = 1;
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 DAT = 0;
 }
 else
 {
 DAT = 1;
 _nop_();
 _nop_();
 DAT = 0;
 _nop_();
 _nop_();
 }
 
 g <<= 1;
 }
 
 for (i = 8; i > 0; i--)
 {
 if ((b & 0x80) != 0)
 {
 DAT = 1;
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 DAT = 0;
 }
 else
 {
 DAT = 1;
 _nop_();
 _nop_();
 DAT = 0;
 _nop_();
 _nop_();
 }
 
 one.dat <<= 1;
 }
 }
 
 void delay(void)
 {
 uint16 i,j;
 for (i = 0; i < 255; i++)
 {
 for (j = 0; j < 255; j++)
 {
 ;
 }
 }
 }
 
 void main(void)
 {
 while (1)
 {
 reset();
 send_data(1,0,0);
 send_data(0,3,0);
 send_data(0,0,255);
 }
 }
 
 
   
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 
 |