51单片机学习

时间:2025-03-07 07:33:25

静态数码管显示

unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void Nixie(unsigned char Location,Number)
{
    switch(Location)
    {
        case 1:P2_4=1;P2_3=1;P2_2=1;break;
        case 2:P2_4=1;P2_3=1;P2_2=0;break;
        case 3:P2_4=1;P2_3=0;P2_2=1;break;
        case 4:P2_4=1;P2_3=0;P2_2=0;break;
        case 5:P2_4=0;P2_3=1;P2_2=1;break;
        case 6:P2_4=0;P2_3=1;P2_2=0;break;
        case 7:P2_4=0;P2_3=0;P2_2=1;break;
        case 8:P2_4=0;P2_3=0;P2_2=0;break;
    }
    P0=NixieTable[Number];
}

void main()
{
    Nixie(1,0);
    while(1)
    {
    
    }
}

动态数码管显示

#include <>
unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void Delay(unsigned int xms)        
{    
    unsigned char i, j;
    while(xms)
    {
        i = 2;
        j = 239;
        do
            {
            while (--j);
            }     
        while (--i);
        xms--;
    }
    
}

void Nixie(unsigned char Location,Number)
{
    switch(Location)
    {
        case 1:P2_4=1;P2_3=1;P2_2=1;break;
        case 2:P2_4=1;P2_3=1;P2_2=0;break;
        case 3:P2_4=1;P2_3=0;P2_2=1;break;
        case 4:P2_4=1;P2_3=0;P2_2=0;break;
        case 5:P2_4=0;P2_3=1;P2_2=1;break;
        case 6:P2_4=0;P2_3=1;P2_2=0;break;
        case 7:P2_4=0;P2_3=0;P2_2=1;break;
        case 8:P2_4=0;P2_3=0;P2_2=0;break;
    }
    P0=NixieTable[Number];
    Delay(1);
    P0=0x00;
}

void main()
{
    while(1)
    {
        Nixie(1,2);
        //Delay(10);
        Nixie(2,0);
        //Delay(10);
        Nixie(3,0);
        //Delay(10);
        Nixie(4,4);
        //Delay(10);
        Nixie(5,0);
        //Delay(10);
        Nixie(6,6);
        //Delay(10);
        Nixie(7,1);
        //Delay(10);
        Nixie(8,8);
        //Delay(10);
    }
}

LCD1602调试

#include <>
#include ""
#include ""

int Result = 0;

void main()
{
    LCD_Init();
    //LCD_ShowChar(1,1,'H');
    //LCD_ShowChar(1,2,'E');
    //LCD_ShowChar(1,3,'L');
    //LCD_ShowChar(1,4,'L');
    //LCD_ShowChar(1,5,'O');
    
    //LCD_ShowString(1,5,"NIXIAK66");
    
    //LCD_ShowNum(1,5,2004,4);
    //LCD_ShowNum(2,6,618,3);
    
    //LCD_ShowSignedNum(1,1,-20000,5);
    
    //LCD_ShowHexNum(1,1,0xA8,2);
    
    //LCD_ShowBinNum(1,1,1001110110010101,16);
    while(1)
    {
        Result++;
        LCD_ShowNum(1,1,Result,3);
        Delay(1000);
        if(Result == 999)
        {
        Result = 0;
        }
    }
}