hi men!
em có cái mạch như sau:
Uploaded with ImageShack.us
code:
khi có tín hiệu ngắt ngoài INT0 em muốn nó thực hiện phép toán (100 - num*2) nhưng loai hoay hoài vẫn k ra có pro nào giúp em đoạn code đó k?
thanks
em có cái mạch như sau:
Uploaded with ImageShack.us
code:
#include <REGX51.H>
#include <stdio.h>
#include <math.h>
long int num,i;
unsigned char donvi,nghin,tram,chuc;
M[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 };
void delay(unsigned long int t)
{
for(i=0;i<=t;++i);
}
void dung(void) /*hien chu dung*/
{
P3=0x80;
P0=0x90;//g
delay(100);
P3=0x40;
P0=0xc8;//n
delay(100);
P3=0x20;
P0=0xc1;//u
delay(100);
P3=0x10;
P0=0xa1;//d
delay(100);
}
void hienthi(int num)
{
nghin=num/1000;
tram=(num%1000)/100;
chuc = ((num%1000)%100)/10;
donvi = ((num%1000)%100)%10;
P3=0x80;
P0=M[donvi];
delay(100);
P3=0x40;
P0=M[chuc];
delay(100);
P3=0x20;
P0=M[tram];
delay(100);
P3=0x10;
P0=M[nghin];
delay(100);
}
void main (void)
{
IE=0x84;
IT1=1;
num=0;
while(1)
{
if(num<=9999)
hienthi(num);
else
dung();
}
}
void ngat1(void) interrupt 2
{
num++;
}
#include <stdio.h>
#include <math.h>
long int num,i;
unsigned char donvi,nghin,tram,chuc;
M[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 };
void delay(unsigned long int t)
{
for(i=0;i<=t;++i);
}
void dung(void) /*hien chu dung*/
{
P3=0x80;
P0=0x90;//g
delay(100);
P3=0x40;
P0=0xc8;//n
delay(100);
P3=0x20;
P0=0xc1;//u
delay(100);
P3=0x10;
P0=0xa1;//d
delay(100);
}
void hienthi(int num)
{
nghin=num/1000;
tram=(num%1000)/100;
chuc = ((num%1000)%100)/10;
donvi = ((num%1000)%100)%10;
P3=0x80;
P0=M[donvi];
delay(100);
P3=0x40;
P0=M[chuc];
delay(100);
P3=0x20;
P0=M[tram];
delay(100);
P3=0x10;
P0=M[nghin];
delay(100);
}
void main (void)
{
IE=0x84;
IT1=1;
num=0;
while(1)
{
if(num<=9999)
hienthi(num);
else
dung();
}
}
void ngat1(void) interrupt 2
{
num++;
}
thanks
Comment