#include<reg51.h> //#include"delay.h" //#include"74hc595.h" #ifndef _74hc595_h_ #define _74hc595_h_ sbit ds=P3^0; //connect to serial input pin of 74hc595 sbit clk=P3^1; //connect to clock input sbit _mr=P3^2; //connect to reset input #define rst_74hc595_mr=0;_mr=1; //to reset a device //routine to convert 8bit parellel to 1bit serial msb first void write_74hc595(unsigned char dat) { unsigned char i; for(i=0;i<=7;i++) { clk=0; ds=(dat&(0x80>>1))?1:0; clk=1; } //extra clock for moving from shift register to storage register clk=0; clk=1; //rst_74hc595 //reset shift register(optional) } void main() { unsigned int i; for(i=0;i<=255;i++) { write_74hc595(i); //delay_ms(500); } while(1); }
Sunday, 7 December 2014
Embedded C code for UART serial communication
Posted by Madan
Posted on 00:00