Programa em C:
#include <8052.h>
//Button_Pin = P3_2; // Declare Button_Pin. It will be used by Button Library.
// End Button connections
bit oldstate; // Old state flag
void MSDelay(unsigned int);
void main() {
P3 = 255; // Configure PORT0 as input
P0 = 0xAA; // Initial PORT2 value
P1 = 0xFF;
oldstate = 1;
while(1)
{
if (P3^2==1) // Detect logical one
//oldstate = 0; // Update flag
//if (oldstate && (P3_2=0)) { // Detect one-to-zero transition
{
P0 = ~P0; // Invert PORT2
MSDelay(50);
P0 = ~P0;
MSDelay (50);
//oldstate = 0; // Update flag
}
else
P1 = 0x10;
// Endless loop
}
}
void MSDelay (unsigned int itime)
{
unsigned int i, j;
for (i=0;i<itime;i++)
for (j=0;j<1275;j++);
}
######################################
/*------------www.szjcdz.cn----------------------
Modified by Solucionatica in 28 august 2014
------------------------------------------------*/
#include<8052.h>
#define DataPort P0
//sbit LATCH1 = P2^6; comment this two lines to compile properly with MCU 8051 IDE (linux version)
//sbit LATCH2 = P2^7;
unsigned char code DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char TempData[8];
void Delay(unsigned int t);
void Display(unsigned char FirstBit,unsigned char Num);
main()
{
unsigned int num;
unsigned int j;
while(1)
{
j++;
if(j==200)
{
j=0;
num++;
if(num==1000)
num=0;
}
TempData[0]=DuanMa[num/100];
TempData[1]=DuanMa[(num%100)/10];
TempData[2]=DuanMa[(num%100)%10];
Display(0,3);
TempData[2]=DuanMa[num/100];
TempData[1]=DuanMa[(num%100)/10];
TempData[0]=DuanMa[(num%100)%10];
Display(5,3);
}
}
void Delay(unsigned int t)
{
while(--t);
}
/*------------------------------------------------
------------------------------------------------*/
void Display(unsigned char FirstBit,unsigned char Num)
{
unsigned char i;
for(i=0;i<Num;i++)
{
DataPort=0;
P2_6 = 1;
P2_6 = 0;
DataPort=WeiMa[i+FirstBit];
P2_7 = 1;
P2_7 = 0;
DataPort=TempData[i];
P2_6 = 1;
P2_6 = 0;
Delay(200);
}
}
C Program: