2 Digit Up/Down Counter Circuit
อุปกรณ์
- AT89C51 (8051 Microcontroller)
- 2 X 7-Segment Displays (Common Anode)
- 2 X 2N2222 NPN Transistors
- 3 X Push Buttons
- 2 X 10KΩ Resistors
- 2 X 470Ω Resistors
- 8 X 100Ω Resistors
- 11.0592 MHz Crystal
- 2 X 33pF Capacitor
- 10μF/16V Capacitor
- 1KΩ X 8 Resistor Pack
- Mini Breadboard
- 5V Power Supply
- 8051 Programmer
code
#include<reg51.h>
#define SEGMENT P0
sbit switch1=P3^0;
sbit switch2=P3^1;
sbit digit1=P2^0;
sbit digit2=P2^1;
void delay (int);
int x=0,y,z;
unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
void delay (int d)
{
unsigned char i;
for(;d>0;d--)
{
for(i=250;i>0;i--);
for(i=248;i>0;i--);
}
}
void main()
{
switch1=1;
switch2=1;
digit1=1;
digit2=1;
while(1)
{
if(switch1==0)
{
x++;
delay(200);
}
else if(switch2==0)
{
x--;
delay(200);
}
y=x/10;
SEGMENT=ch[y];
digit1=0;
delay(10);
digit1=1;
z=x%10;
SEGMENT=ch[z];
digit2=0;
delay(10);
digit2=1;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น