51单片机——数码管驱动

#include
#include "./delay/delay.h"
#include
#define SEGPORT P0
sbit bit_sel = P2^0;
sbit seg_sel = P2^1;
unsigned char segdata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void main()
{
    unsigned char i;
    //unsigned char temp;  
   //SEGPORT = 0x7f;
   //bit_sel = 0;
   //bit_sel = 1;
   //bit_sel = 0;
   //temp = 0x7f;
 
   while(1)
    { 
       for(i = 0; i < 8; i++)
       {
       SEGPORT = 0x0;
       seg_sel = 1;
       seg_sel = 0;
     
       SEGPORT = 0xff;
       bit_sel = 1;
       bit_sel = 0;
     
         SEGPORT = segdata[i];
         seg_sel = 1;
         seg_sel = 0;
     
       SEGPORT = bitdata[i];
         bit_sel = 1;
         bit_sel = 0;
    
         delay_ms(2);
        }
  }
}

你可能感兴趣的:(单片机)