Chào các bạn. các bạn giúp mình với.mình dùng hai nút để tăng và giảm nhiệt độ( hiển thị bằng led 7 thanh). mình viết code thế này nhung không chạy. không biết sai ở đâu. các bạn giúp mình với. cảm ơn các bạn nhiều. chúc các bạn TRUNG THU vui vẻ.
#include <mega8.h>
#include <delay.h>
#define nut1 PINC.3
#define nut2 PINC.4
#define led PORTC.5
#define a1 PORTD.0
#define b1 PORTD.1
#define c1 PORTD.2
#define d1 PORTD.3
#define a2 PORTD.4
#define b2 PORTD.5
#define c2 PORTD.6
#define d2 PORTD.7
#define a3 PORTB.0
#define b3 PORTB.1
#define c3 PORTB.2
#define d3 PORTB.3
void giai_ma_tram(unsigned char so1)
{
switch(so1)
{
case 0:a1=0;b1=0;c1=0;d1=0;break;
case 1:a1=1;b1=0;c1=0;d1=0;break;
case 2:a1=0;b1=1;c1=0;d1=0;break;
case 3:a1=1;b1=1;c1=0;d1=0;break;
case 4:a1=0;b1=0;c1=1;d1=0;break;
case 5:a1=1;b1=0;c1=1;d1=0;break;
case 6:a1=0;b1=1;c1=1;d1=0;break;
case 7:a1=1;b1=1;c1=1;d1=0;break;
case 8:a1=0;b1=0;c1=0;d1=1;break;
case 9:a1=1;b1=0;c1=0;d1=1;break;
}
}
void giai_ma_chuc(unsigned char so2 )
{
switch(so2)
{
case 0:a2=0;b2=0;c2=0;d2=0;break;
case 1:a2=1;b2=0;c2=0;d2=0;break;
case 2:a2=0;b2=1;c2=0;d2=0;break;
case 3:a2=1;b2=1;c2=0;d2=0;break;
case 4:a2=0;b2=0;c2=1;d2=0;break;
case 5:a2=1;b2=0;c2=1;d2=0;break;
case 6:a2=0;b2=1;c2=1;d2=0;break;
case 7:a2=1;b2=1;c2=1;d2=0;break;
case 8:a2=0;b2=0;c2=0;d2=1;break;
case 9:a2=1;b2=0;c2=0;d2=1;break;
}
}
void giai_ma_donvi(unsigned char so3)
{
switch(so3)
{
case 0:a3=0;b3=0;c3=0;d3=0;break;
case 1:a3=1;b3=0;c3=0;d3=0;break;
case 2:a3=0;b3=1;c3=0;d3=0;break;
case 3:a3=1;b3=1;c3=0;d3=0;break;
case 4:a3=0;b3=0;c3=1;d3=0;break;
case 5:a3=1;b3=0;c3=1;d3=0;break;
case 6:a3=0;b3=1;c3=1;d3=0;break;
case 7:a3=1;b3=1;c3=1;d3=0;break;
case 8:a3=0;b3=0;c3=0;d3=1;break;
case 9:a3=1;b3=0;c3=0;d3=1;break;
}
}
void hien_so(unsigned char so4)
{
unsigned char tram,chuc,donvi;
donvi=so4%10;
so4=so4/10;
chuc=so4%10;
tram=so4/10;
giai_ma_tram(tram);
giai_ma_chuc(chuc);
giai_ma_donvi(donvi);
}
void main(void)
{
unsigned char dem=0;
while (1)
{
if(nut2)
{
while(nut2)
{
;
}
dem++;
}
if(nut1==0&&dem>0)
{
while(nut1)
{
;
}
dem--;
}
hien_so(dem);
};
}
#include <mega8.h>
#include <delay.h>
#define nut1 PINC.3
#define nut2 PINC.4
#define led PORTC.5
#define a1 PORTD.0
#define b1 PORTD.1
#define c1 PORTD.2
#define d1 PORTD.3
#define a2 PORTD.4
#define b2 PORTD.5
#define c2 PORTD.6
#define d2 PORTD.7
#define a3 PORTB.0
#define b3 PORTB.1
#define c3 PORTB.2
#define d3 PORTB.3
void giai_ma_tram(unsigned char so1)
{
switch(so1)
{
case 0:a1=0;b1=0;c1=0;d1=0;break;
case 1:a1=1;b1=0;c1=0;d1=0;break;
case 2:a1=0;b1=1;c1=0;d1=0;break;
case 3:a1=1;b1=1;c1=0;d1=0;break;
case 4:a1=0;b1=0;c1=1;d1=0;break;
case 5:a1=1;b1=0;c1=1;d1=0;break;
case 6:a1=0;b1=1;c1=1;d1=0;break;
case 7:a1=1;b1=1;c1=1;d1=0;break;
case 8:a1=0;b1=0;c1=0;d1=1;break;
case 9:a1=1;b1=0;c1=0;d1=1;break;
}
}
void giai_ma_chuc(unsigned char so2 )
{
switch(so2)
{
case 0:a2=0;b2=0;c2=0;d2=0;break;
case 1:a2=1;b2=0;c2=0;d2=0;break;
case 2:a2=0;b2=1;c2=0;d2=0;break;
case 3:a2=1;b2=1;c2=0;d2=0;break;
case 4:a2=0;b2=0;c2=1;d2=0;break;
case 5:a2=1;b2=0;c2=1;d2=0;break;
case 6:a2=0;b2=1;c2=1;d2=0;break;
case 7:a2=1;b2=1;c2=1;d2=0;break;
case 8:a2=0;b2=0;c2=0;d2=1;break;
case 9:a2=1;b2=0;c2=0;d2=1;break;
}
}
void giai_ma_donvi(unsigned char so3)
{
switch(so3)
{
case 0:a3=0;b3=0;c3=0;d3=0;break;
case 1:a3=1;b3=0;c3=0;d3=0;break;
case 2:a3=0;b3=1;c3=0;d3=0;break;
case 3:a3=1;b3=1;c3=0;d3=0;break;
case 4:a3=0;b3=0;c3=1;d3=0;break;
case 5:a3=1;b3=0;c3=1;d3=0;break;
case 6:a3=0;b3=1;c3=1;d3=0;break;
case 7:a3=1;b3=1;c3=1;d3=0;break;
case 8:a3=0;b3=0;c3=0;d3=1;break;
case 9:a3=1;b3=0;c3=0;d3=1;break;
}
}
void hien_so(unsigned char so4)
{
unsigned char tram,chuc,donvi;
donvi=so4%10;
so4=so4/10;
chuc=so4%10;
tram=so4/10;
giai_ma_tram(tram);
giai_ma_chuc(chuc);
giai_ma_donvi(donvi);
}
void main(void)
{
unsigned char dem=0;
while (1)
{
if(nut2)
{
while(nut2)
{
;
}
dem++;
}
if(nut1==0&&dem>0)
{
while(nut1)
{
;
}
dem--;
}
hien_so(dem);
};
}
Comment