Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: lv8.c
- * Author: NA
- *
- * Created on Decembar 2018
- */
- #include <xc.h>
- #pragma config FOSC=HS,WDTE=OFF,PWRTE=OFF,MCLRE=ON,CP=OFF,CPD=OFF,BOREN=OFF,CLKOUTEN=OFF
- #pragma config IESO=OFF,FCMEN=OFF,WRT=OFF,VCAPEN=OFF,PLLEN=OFF,STVREN=OFF,LVP=OFF
- #define _XTAL_FREQ 8000000
- char brojac=0, gornja=0, donja=0,smjer=0;
- //*********************************************************************
- void write(char eepromAddress, char eepromData)
- {
- unsigned char gie_Status;
- EECON1bits.EEPGD=0;
- EECON1bits.CFGS=0;
- while(WR); // check the WR bit to see if a previous Write operation is in progress
- EEADR=eepromAddress; // Write the address to EEADR.
- EEDATA=eepromData; // load the 8-bit data value to be written in the EEDATA register.
- WREN=1; // Set the WREN bit to enable eeprom operation.
- gie_Status = GIE; // Copy the current Interrupt state
- GIE = 0; // Disable the interrupts
- EECON2=0x55; // Execute the special instruction sequence
- EECON2=0xaa; // Refer the datasheet for more info
- WR=1; // Set the WR bit to trigger the eeprom write operation.
- GIE = gie_Status; // Restore the interrupts
- WREN=0; // Disable the EepromWrite
- }
- //*********************************************************************
- char read(char eepromAddress)
- {
- EECON1bits.EEPGD=0;
- EECON1bits.CFGS=0;
- while(RD || WR); // check the WR&RD bit to see if a RD/WR is in progress
- EEADR=eepromAddress; // Write the address to EEADR.
- RD = 1; // Set the RD bit to trigger the eeprom read operation.
- return(EEDATA); // Return the data read form eeprom.
- }
- //**********************************************************************
- write(0x00,smjer);
- write(0x01,donja); // ovdje će bit neki konkretni brojevi umjesto varijabli
- write(0x02,gornja);
- //****************************
- void funkcija_tajmera (){
- brojac=read(0x03);
- if (smjer){
- if(brojac==gornja) brojac=donja;
- brojac++;
- write(0x03,brojac);
- PORTB=brojac;
- } else if(!smjer) {
- if(brojac==donja) brojac=gornja;
- brojac--;
- write(0x03,brojac);
- PORTB=brojac;
- }
- }
- //****************************
- void main(void){
- // Na PORTB ce biti ispisivane vrijednosti brojaca
- TRISB=0x00;
- ANSELB=0x00;
- LATB=0x00;
- PORTB=0x00;
- smjer = read(0x00);
- donja = read(0x01);
- gornja = read(0x02);
- if(smjer) brojac=donja; //ako je smjer=1 broji unaprijed
- else brojac=gornja;
- write(0x03,brojac);
- while(1) {
- Time (); // ovdje će bit neka funkcija koja će svake sekunde uvećavati brojac
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement