www.pudn.com > plc_1.zip > Led_1.c


#include "reg51.h" 
 
void Show(unsigned char); 
extern bit light_on; 
sbit LED_CLK = P1^4; 
sbit LED_DATA = P1^5; 
unsigned char code LED[16] = {0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f, 
                              0x01,0x09,0x11,0xc1,0x63,0x85,0x61,0x71}; 
 
void Led_Show(unsigned char out_data, bit point ) 
{ 
   unsigned char temp_data; 
 
   temp_data = out_data & 0x0f; 
   temp_data = LED[temp_data]; 
   if (light_on == 0) 
   { 
      if (point == 1) 
         temp_data = temp_data & 0xfe; 
   } 
   else  
         temp_data = 0xff; 
   Show(temp_data); 
   temp_data = (out_data & 0xf0) >> 4; 
   temp_data = LED[temp_data]; 
   if (light_on == 0) 
   { 
      if (point == 1) 
          temp_data = temp_data & 0xfe; 
   } 
   else  
          temp_data = 0xff; 
   Show(temp_data); 
} 
 
void Show(unsigned char out_data) 
{  
   unsigned char and_data = 1; 
 
   LED_CLK = 0; 
   do {  
        if (out_data & and_data)   
		    LED_DATA = 1; 
        else  
            LED_DATA = 0; 
        LED_CLK = 1; 
		LED_CLK = 0; 
       }while(and_data = and_data << 1); 
} 
 
void On_Light(unsigned char out_data,bit b,unsigned char on_data) 
{ 
    Show(on_data); 
    Led_Show(out_data,b); 
}