
LICZNIK.c
Makefile
06-Licznik.zip

/**************************************/
/* ARE 2009 + AiR 2024 */
/* e-mail: [email protected] */
/* www : are.net.pl */
/**************************************/
/* 43 linia w Makefile MCU = atmega16 */
/* JUŻ ZMIENIONA na MCU = atmega32 */
/**************************************/
// #define F_CPU 1000000UL // 1 MHz
#define F_CPU 8000000UL // 8 MHz
//#define F_CPU 14.7456E6
#include <util/delay.h>
#include <avr/io.h>
void delay_ms( int ms) {
volatile long unsigned int i;
for(i=0;i<ms;i++)
_delay_ms(1);
}
int main(void) {
//ustalenie kierunku pinow
DDRA = 0x00;
DDRD = 0xFF;
PORTA = 0xFF;
PORTD = 0x00;
//zdefiniowanie zmiennej odpowiadajacej za opoznienia
int ms=500;
int i=0;
char h_sw1 = 0xFF;
char h_sw5 = 0xFF;
char h_sw9 = 0xFF;
char h_sw13 = 0xFF;
char pom1;
//ustawienie stanu poczatkowego portu
PORTD=0x03;
// LICZNIK
while(1) {
pom1 = PINA;
h_sw1 = ( h_sw1 <<1 ) + ( pom1 & 0x01 );
h_sw5 = ( h_sw5 <<1 ) + ( (pom1 & 0x02) >>1 );
h_sw9 = ( h_sw9 <<1 ) + ( (pom1 & 0x04) >>2 );
h_sw13 = ( h_sw13 <<1 ) + ( (pom1 & 0x08) >>3 );
PORTD = pom1; // TEST 0
// PORTD = h_sw1; // TEST 1
// PORTD = h_sw5; // TEST 2
// PORTD = h_sw9; // TEST 3
// PORTD = h_sw13; // TEST 4
delay_ms(ms);
};
return(0);
}
/* ========== ORGINAŁ ==========
int main(void) {
//ustalenie kierunku pinow
DDRD=0xFF;
//zdefiniowanie zmiennej odpowiadajacej za opoznienia
int ms=100;
int i=0;
//ustawienie stanu poczatkowego portu
PORTD=0x03;
//"biegajace" diody
while(1) {
for(i=0;i<6;i++) {
PORTD=~(0x03<<i);
delay_ms(ms);
}
for(i=6;i>0;i--) {
PORTD=~(0x03<<i);
delay_ms(ms);
}
};
return(0);
}
==============================*/

