Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 1. Spojit 7seg, znamenke na PORTB, segmente na PORTD
- 2. Key1 datum, Key2 godina
- 3. Implementirat da kad se Key3 pritisne da se moze mijenjat godina - na Key1 se povecava, Key2 smanjuje,
- kad se opet Key3 pritisne - Key1 prikazuje opet datum, a Key2 godinu, znaci sa Key3 se mijenja stanje sto
- Key1 i Key2 rade -- koliko-toliko napravljeni taj zadatak
- */
- #define F_CPU 7372800UL
- #include <avr/io.h>
- #include <util/delay.h>
- int main(void)
- {
- DDRD = 0xff;
- PORTD = 0x00;
- DDRB = 0xf0;
- PORTB = 0x0f;
- uint8_t date[] = {0x5b, 0x5b, 0x3f, 0x4f};
- uint8_t year[] = {0x5b, 0x3f, 0x06, 0x07};
- uint8_t values[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
- uint8_t i, state = 0;
- uint8_t counter = 7;
- uint8_t funkcija = 0;
- while (1)
- {
- if(bit_is_clear(PINB, 2))
- {
- funkcija ^= 0x01;
- }
- if(funkcija == 0)
- {
- PORTB = 0x0f;
- if(bit_is_clear(PINB, 0)){
- state = 1;
- PORTD = 0x00;
- PORTB = 0x0f;
- }else if(bit_is_clear(PINB, 1)){
- state = 2;
- PORTD = 0x00;
- PORTB = 0x0f;
- }
- if(state == 1){
- for(i = 0; i < 4; i++){
- PORTD = date[i];
- PORTB = _BV(4 + i);
- _delay_us(1000);
- }
- } else if(state == 2){
- for(i = 0; i < 4; i++){
- PORTD = year[i];
- PORTB = _BV(4 + i);
- _delay_us(1000);
- }
- }
- }
- else if(funkcija == 1)
- {
- PORTB = 0x0f;
- for(i = 0; i < 4; i++)
- {
- PORTD = year[i];
- PORTB = _BV(4 + i);
- if(bit_is_clear(PINB, 0) && (PORTB == _BV(7)))
- {
- if(counter > 9){
- counter = 0;
- }
- counter += 1;
- year[3] = values[counter];
- _delay_ms(200);
- } else if(bit_is_clear(PINB, 1) && (PORTB == _BV(7)))
- {
- if(counter <= 0){
- counter = 0;
- }
- counter -= 1;
- year[3] = values[counter];
- _delay_ms(200);
- }
- _delay_us(1000);
- }
- }
- _delay_us(10); // za debounce
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement