MyTetra Share
Делитесь знаниями!
74HC595N
Время создания: 30.11.2017 14:56
Раздел: Electronics - Microcontrollers - AVR8 - AVR GCC - C_PROJ

#define F_CPU 8000000L

#define DEVICE (__AVR_ATmega8__)


#define NOP asm volatile("NOP"::)


#define HC595 PORTB

#define DS 0

#define ST 2

#define SH 1


#define DATA_HI HC595 |= (1<<DS)

#define DATA_LOW HC595 &= ~(1<<DS)

#define CLK_HI HC595 |= (1<<SH)

#define CLK_LOW HC595 &= ~(1<<SH)

#define LOCK_HI HC595 |= (1<<ST)

#define LOCK_LOW HC595 &= ~(1<<ST)


//for indicator with common cathode

//D0..D7 == A,B,C,D,F,G,DP

#define c1 0x06;

#define c2 0x5B;

#define c3 0x4F;

#define c4 0x66;

#define c5 0x6D;

#define c6 0x7D;

#define c7 0x07;

#define c8 0x7F;

#define c9 0x6F;

#define c0 0x3F;


#define CHECKBIT(BYTE,BIT) (BYTE & (1<<BIT))


//#define RAZR16

#ifndef RAZR16

#define RAZR 8

#else

#define RAZR 16

#endif


#define RAZR 8


#include <avr/io.h>

#include <avr/interrupt.h>


#if 0

volatile unsigned int TCNT = 0; //timer overflow


//================================================================================

// INTERNAL INT SECTION

//================================================================================


ISR(TIMER0_OVF_vect)

{

//TCNT0 == 1 - 0,125us, 8 - 1us, 256 - 32us

++TCNT;

}

#endif


//================================================================================

// FUNCTION SECTION

//================================================================================

int main(void)

{

DDRB = 0x07; //0000.0111 DDRB

CLK_LOW;

LOCK_LOW;


for(;;)

{

unsigned char data = c6;

unsigned char bit_counter = RAZR;

do

{

DATA_LOW;

CLK_LOW;

if( CHECKBIT(data, --bit_counter) ) //if bit in data == 1

DATA_HI;

CLK_HI;

} while(bit_counter);


CLK_LOW;

LOCK_HI;

NOP;

NOP;

NOP;

LOCK_LOW;

}

return 0;

}


Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования