Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XTAL_FREQ 20000000
- #define RS RA0
- #define EN RA1
- #define D4 RA2
- #define D5 RA3
- #define D6 RA4
- #define D7 RA5
- #include <xc.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "lcd1.h"
- #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
- #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT enabled)
- #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
- #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
- #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
- #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
- #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
- void main(){
- PORTA=0x00;
- TRISA=0x00;
- TRISD=0x00;
- PORTD=0x00;
- TRISB=0x00;
- PORTB=0x00;
- lcd_init();
- lcd_clear();
- lcd_set_cursor(1,1);
- lcd_write_string("00:59");
- // Array of values for BCD to 7seg
- char NEW_LED[10][4] = {{0,0,0,0}, {0,0,0,1},{0,0,1,0}, {0,0,1,1}, {0,1,0,0}, {0,1,0,1}, {0,1,1,0}, {0,1,1,1}, {1,0,0,0}, {1,0,0,1}};
- // Total number of seconds
- int br_sekundi = 0;
- while(1){
- int sekunde = (br_sekundi % 60);
- /*** SEKUNDE LIJEVE ***/
- int sek_l = sekunde / 10;
- PORTDbits.RD0 = NEW_LED[sek_l][3];
- PORTDbits.RD1 = NEW_LED[sek_l][2];
- PORTDbits.RD2 = NEW_LED[sek_l][1];
- PORTDbits.RD3 = NEW_LED[sek_l][0];
- /*** SEKUNDE DESNE ***/
- int sek_d = sekunde % 10;
- PORTDbits.RD4 = NEW_LED[sek_d][3];
- PORTDbits.RD5 = NEW_LED[sek_d][2];
- PORTDbits.RD6 = NEW_LED[sek_d][1];
- PORTDbits.RD7 = NEW_LED[sek_d][0];
- /********************* MINUTE ***********************/
- int minute = br_sekundi / 60;
- /**** MINUTE LIJEVE *****/
- int minute_l = minute / 10;
- PORTBbits.RB0 = NEW_LED[minute_l][3];
- PORTBbits.RB1 = NEW_LED[minute_l][2];
- PORTBbits.RB2 = NEW_LED[minute_l][1];
- PORTBbits.RB3 = NEW_LED[minute_l][0];
- /**** MINUTE DESNE *****/
- int minute_d = minute % 10;
- PORTBbits.RB4 = NEW_LED[minute_d][3];
- PORTBbits.RB5 = NEW_LED[minute_d][2];
- PORTBbits.RB6 = NEW_LED[minute_d][1];
- PORTBbits.RB7 = NEW_LED[minute_d][0];
- /*
- if(sek_d == 9 && sek_l == 0 && minute_l == 0 && minute_d == 0){
- lcd_clear();
- lcd_set_cursor(1,1);
- lcd_write_string("00:59");
- lcd_set_cursor(2,1);
- lcd_write_string("Vrijeme je dobro");
- }
- */
- __delay_ms(500);
- br_sekundi ++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement