コード例 #1
0
ファイル: HC595.c プロジェクト: roberttruong/ELEC3117-UQT
/*

Main High level function to write a single byte to
Output shift register 74HC595. 

Arguments:
   single byte to write to the 74HC595 IC

Returns:
   NONE

Description:
   The byte is serially transfered to 74HC595
   and then latched. The byte is then available on
   output line Q0 to Q7 of the HC595 IC.

*/
void HC595Write(uint8_t data)
{
   //Send each 8 bits serially

   //Order is MSB first
   for(uint8_t i=0;i<8;i++)
   {
      //Output the data on DS line according to the
      //Value of MSB
      if(data & 0b10000000)
      {
         //MSB is 1 so output high

         HC595DataHigh();
      }
      else
      {
         //MSB is 0 so output high
         HC595DataLow();
      }

      HC595Pulse();  //Pulse the Clock line
      data=data<<1;  //Now bring next bit at MSB position

   }

   //Now all 8 bits have been transferred to shift register
   //Move them to output latch at one
   HC595Latch();
}
コード例 #2
0
ファイル: code.c プロジェクト: eSenpai/atmega
void HC595SendByte(uint8_t data){
    for(uint8_t i = 0; i < 8; i++){
	if(data & 0b10000000){
	    HC595DataHigh();
	}else{
	    HC595DataLow();
	}
	HC595Pulse();
	data = data << 1;
    }
    HC595Latch();
    CD4017Pulse();
    _delay_ms(1);
}