Advertisement
Guest User

lv8pa

a guest
Dec 11th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.79 KB | None | 0 0
  1. /*
  2.  * File:   lv8.c
  3.  * Author: NA
  4.  *
  5.  * Created on Decembar 2018
  6.  */
  7.  
  8.  
  9. #include <xc.h>
  10.  
  11. #pragma config FOSC=HS,WDTE=OFF,PWRTE=OFF,MCLRE=ON,CP=OFF,CPD=OFF,BOREN=OFF,CLKOUTEN=OFF
  12. #pragma config IESO=OFF,FCMEN=OFF,WRT=OFF,VCAPEN=OFF,PLLEN=OFF,STVREN=OFF,LVP=OFF
  13.  
  14. #define _XTAL_FREQ 8000000
  15.  
  16.  
  17. char brojac=0, gornja=0, donja=0,smjer=0;
  18. //*********************************************************************
  19. void write(char eepromAddress, char eepromData)
  20. {
  21.     unsigned char gie_Status;
  22.    
  23.     EECON1bits.EEPGD=0;
  24.     EECON1bits.CFGS=0;
  25.    
  26.    
  27.     while(WR);            // check the WR bit to see if a previous Write operation is in progress
  28.     EEADR=eepromAddress;  // Write the address to EEADR.
  29.     EEDATA=eepromData;    // load the 8-bit data value to be written in the EEDATA register.
  30.     WREN=1;               // Set the WREN bit to enable eeprom operation.
  31.     gie_Status = GIE;     // Copy the current Interrupt state
  32.     GIE = 0;              // Disable the interrupts
  33.     EECON2=0x55;          // Execute the special instruction sequence
  34.     EECON2=0xaa;          // Refer the datasheet for more info
  35.     WR=1;                 // Set the WR bit to trigger the eeprom write operation.
  36.     GIE = gie_Status;     // Restore the interrupts
  37.     WREN=0;               // Disable the EepromWrite
  38. }
  39. //*********************************************************************
  40. char read(char eepromAddress)
  41. {
  42.     EECON1bits.EEPGD=0;
  43.     EECON1bits.CFGS=0;
  44.     while(RD || WR);           // check the WR&RD bit to see if a RD/WR is in progress
  45.     EEADR=eepromAddress;       // Write the address to EEADR.
  46.     RD = 1;                    // Set the RD bit to trigger the eeprom read operation.
  47.     return(EEDATA);            // Return the data read form eeprom.
  48. }
  49. //**********************************************************************
  50.  
  51. write(0x00,smjer);
  52. write(0x01,donja);  // ovdje će bit neki konkretni brojevi umjesto varijabli
  53. write(0x02,gornja);
  54. //****************************
  55. void funkcija_tajmera (){
  56.     brojac=read(0x03);
  57.     if (smjer){
  58.         if(brojac==gornja) brojac=donja;
  59.         brojac++;
  60.         write(0x03,brojac);
  61.         PORTB=brojac;
  62.     } else if(!smjer) {
  63.         if(brojac==donja) brojac=gornja;
  64.         brojac--;
  65.         write(0x03,brojac);
  66.         PORTB=brojac;
  67.     }
  68. }
  69. //****************************
  70.  
  71. void main(void){
  72. // Na PORTB ce biti ispisivane vrijednosti brojaca
  73.     TRISB=0x00;
  74.     ANSELB=0x00;
  75.     LATB=0x00;
  76.     PORTB=0x00;
  77.    
  78.     smjer = read(0x00);
  79.     donja = read(0x01);
  80.     gornja = read(0x02);
  81.    
  82. if(smjer) brojac=donja;  //ako je smjer=1 broji unaprijed
  83. else brojac=gornja;
  84. write(0x03,brojac);
  85.  
  86.     while(1) {
  87.         Time (); // ovdje će bit neka funkcija koja će svake sekunde uvećavati brojac
  88.        
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement