stankovic96

[P.E.] dsPIC30 - Turn LEDs On and Off (Rise and Fall)

Oct 19th, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. /*
  2.  * File:   newmain.c
  3.  * Author: Stefan Stankovic
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include<p30fxxxx.h>
  9.  
  10. _FOSC(CSW_FSCM_OFF & XT_PLL4);//instruction takt je isti kao i kristal
  11. _FWDT(WDT_OFF);
  12.  
  13. void delay();
  14. void dioda(unsigned char);
  15. unsigned int broj1,broj2,br=0; //za delay i brojac
  16.  
  17. unsigned int pat=0x0001,temp=0x0000; // patern i temp
  18. unsigned char dozvola=1;// dozvola=1 pale se diode
  19.  
  20.  
  21. int main(int argc, char** argv) {
  22.    
  23.    
  24.  
  25.     ADPCFG=0xffff;//defini?emo da pin B4 nije analogni vec digitalni
  26.  
  27.     TRISB=0x0000;//konfigurisemo kao izlaz
  28.    
  29.  
  30.     while(1)
  31.     {
  32.        
  33.        
  34.        if(dozvola==1){
  35.            temp=temp | pat;
  36.            LATB=temp;
  37.            delay();
  38.            pat=pat<<1;
  39.            
  40.        }
  41.        else{
  42.            temp=temp>>1;
  43.            LATB=temp;
  44.            delay();
  45.            
  46.        }
  47.        
  48.        
  49.        if(temp==0x1fff){
  50.            dozvola=0;
  51.            pat=0x0001;
  52.        }
  53.        if(temp==0x0000)
  54.            dozvola=1;
  55.        
  56.  
  57.     }// while    
  58.     return (EXIT_SUCCESS);
  59. }//main
  60.  
  61. void delay()
  62. {
  63.     for(broj1=0;broj1<300;broj1++)
  64.         for(broj2=0;broj2<300;broj2++);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment