Advertisement
Guest User

samel kod

a guest
Feb 7th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _XTAL_FREQ 20000000
  2.  
  3. #define RS RA0
  4. #define EN RA1
  5. #define D4 RA2
  6. #define D5 RA3
  7. #define D6 RA4
  8. #define D7 RA5
  9.  
  10. #include <xc.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "lcd1.h"
  14.  
  15. #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
  16. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
  17. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT enabled)
  18. #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
  19. #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)
  20. #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
  21. #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
  22. #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
  23.  
  24. void main(){
  25.     PORTA=0x00;
  26.     TRISA=0x00;
  27.  
  28.    
  29.     TRISD=0x00;
  30.     PORTD=0x00;
  31.     TRISB=0x00;
  32.     PORTB=0x00;
  33.    
  34.     lcd_init();
  35.     lcd_clear();
  36.     lcd_set_cursor(1,1);
  37.     lcd_write_string("00:59");
  38.    
  39.     // Array of values for BCD to 7seg
  40.     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}};    
  41.     // Total number of seconds
  42.     int br_sekundi = 0;
  43.    
  44.    
  45.    
  46.     while(1){
  47.         int sekunde = (br_sekundi % 60);
  48.        
  49.         /*** SEKUNDE LIJEVE ***/
  50.         int sek_l = sekunde / 10;
  51.         PORTDbits.RD0 = NEW_LED[sek_l][3];
  52.         PORTDbits.RD1 = NEW_LED[sek_l][2];
  53.         PORTDbits.RD2 = NEW_LED[sek_l][1];
  54.         PORTDbits.RD3 = NEW_LED[sek_l][0];
  55.        
  56.         /*** SEKUNDE DESNE ***/
  57.         int sek_d = sekunde % 10;
  58.         PORTDbits.RD4 = NEW_LED[sek_d][3];
  59.         PORTDbits.RD5 = NEW_LED[sek_d][2];
  60.         PORTDbits.RD6 = NEW_LED[sek_d][1];
  61.         PORTDbits.RD7 = NEW_LED[sek_d][0];
  62.  
  63.  
  64.         /********************* MINUTE ***********************/      
  65.         int minute = br_sekundi / 60;
  66.        
  67.         /**** MINUTE LIJEVE *****/
  68.         int minute_l = minute / 10;
  69.         PORTBbits.RB0 = NEW_LED[minute_l][3];
  70.         PORTBbits.RB1 = NEW_LED[minute_l][2];
  71.         PORTBbits.RB2 = NEW_LED[minute_l][1];
  72.         PORTBbits.RB3 = NEW_LED[minute_l][0];
  73.        
  74.         /****  MINUTE DESNE *****/
  75.         int minute_d = minute % 10;
  76.         PORTBbits.RB4 = NEW_LED[minute_d][3];
  77.         PORTBbits.RB5 = NEW_LED[minute_d][2];
  78.         PORTBbits.RB6 = NEW_LED[minute_d][1];
  79.         PORTBbits.RB7 = NEW_LED[minute_d][0];
  80.        
  81.         /*
  82.        
  83.         if(sek_d == 9 && sek_l == 0 && minute_l == 0 && minute_d == 0){
  84.         lcd_clear();
  85.         lcd_set_cursor(1,1);
  86.         lcd_write_string("00:59");
  87.         lcd_set_cursor(2,1);
  88.         lcd_write_string("Vrijeme je dobro");
  89.        
  90.         }
  91.         */
  92.         __delay_ms(500);
  93.        
  94.         br_sekundi ++;
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement