Truyền dữ liệu thanh ghi dịch 74hc595
Chân Clock: E2
Chân data: E0
Level1: Xuất nhấp nháy dữ liệu 8 bit ra thanh ghi dịch:
#include <16F877A.h>
#include <DEFS_16F877A.h>
#device *=16 ADC=10
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
//=========================functions use========================================
void load_eep_macdinh();
Void clock();
Void sent_data();
int8 k,data;
int8 data1=0b00001111;
#define out_data RE1
//======================================functions use===========================
/********************* Ham main *************************/
void main()
{
set_tris_B(0);
set_tris_D(0);
set_tris_E(0);
set_tris_A(0xff);
out_data=0;
While(true)
{
data=data1;
sent_data();
out_data=1;
delay_ms(500);
out_data=0;
delay_ms(500);
}
}
Void sent_data()
{
for(k=1;k<=8;k++)
{
#bit in=data.7
if(in==1)
{output_high(PIN_E0);}
else
{output_low(PIN_E0);}
clock();
data = data<<1;
}
}
Void clock()
{
output_high(PIN_E2);
output_low(PIN_E2);
}
Level2: Xuất nhấp nháy dữ liệu 1 mảng ra thanh ghi dịch:
#include <16F877A.h>
#include <DEFS_16F877A.h>
#device *=16 ADC=10
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
//=========================functions use========================================
void load_eep_macdinh();
Void clock();
Void sent_data();
int8 i,k,data;
int8 data1[]={0b00000000,0b00000001,0b00000010,0b00000011,0b00 000100,0b00000101,0b00000110,0b00000111,0b00001000 ,0b00001001};
#define out_data RE1
//======================================functions use===========================
/********************* Ham main *************************/
void main()
{
set_tris_B(0);
set_tris_D(0);
set_tris_E(0);
set_tris_A(0xff);
out_data=0;
While(true)
{
for(i=0;i<10;i++)
{
data=data1[i];
sent_data();
out_data=1;
delay_ms(500);
out_data=0;
delay_ms(500);
}
}
}
Void sent_data()
{
for(k=0;k<8;k++)
{
#bit in=data.7
if(in==1)
{output_high(PIN_E0);}
else
{output_low(PIN_E0);}
clock();
data = data<<1;
}
}
Void clock()
{
output_high(PIN_E2);
output_low(PIN_E2);
}
Chú ý: khi truyền dữ liệu ra thanh ghi dịch thì out_data phải xuống mức 0, nếu không sẽ bị lỗi!!!!!!!!!!. Các level khác .....hôm khác vậy!!!!!!!!
|