PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   [HELP] hiển thị 4 led 7 đoạn bằng 74HC595 (http://www.picvietnam.com/forum/showthread.php?t=32419)

saobang 13-06-2013 08:38 PM

[HELP] hiển thị 4 led 7 đoạn bằng 74HC595
 
2 Attachment(s)
Em làm mạch quét 4 led 7 đoạn dùng IC 74HC595
Mấy anh chị xem giúp em code hoặc mạch có gì sai ko mà khi em cho hiển thị thì chỉ led 1,2 hiển thị đúng còn led 3,4 thì nó đổi vị trí các đoạn của led 7 ví dụ như cho nó sáng đoạn A thì nó sáng đoạn B, B thì thành C….
Code với sơ đồ nguyên lý trong file đính kèm! Em cảm ơn trước!
code:
#include <16f877A.h>
#device *=16, ADC = 10
#use delay(clock=20000000)
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP,NOCPD, NOWRT
//==============================DEFINE============== ===================
#define DAT PIN_B5
#define SCK PIN_B6
#define SCL PIN_B7
//========================VARIABLE================== ===================
unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
//unsigned char N[10]={0x60,0xFC,0x52,0x58,0xcc,0x49,0x41,0x7c,0x40,0x4 8};
//======================FUNCTION==================== ===================
void display(int x,int y,int z,int t)
{
int i,temp;
for (i=0;i<8;i++){temp=x;temp=temp&0x80;if(temp==0x80) output_high(DAT);else output_low(DAT);x*=2;output_low(SCK);output_high(S CK);}
for (i=0;i<8;i++){temp=y;temp=temp&0x80;if(temp==0x80) output_high(DAT);else output_low(DAT);y*=2;output_low(SCK);output_high(S CK);}
for (i=0;i<8;i++){temp=z;temp=temp&0x80;if(temp==0x80) output_high(DAT);else output_low(DAT);z*=2;output_low(SCK);output_high(S CK);}
for (i=0;i<8;i++){temp=t;temp=temp&0x80;if(temp==0x80) output_high(DAT);else output_low(DAT);t*=2;output_low(SCK);output_high(S CK);}
output_low(SCL);delay_ms(10);
output_high(SCL);
}

void main()
{
while(true)
{
display(M[1],M[2],M[3],M[4]);
delay_ms(200);
}
}


Múi giờ GMT. Hiện tại là 02:57 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam