stankovic96

[PE]dsPIC_shift_led_delay_ms

Nov 8th, 2018
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <p30fxxxx.h>
  2.  
  3.  
  4. #include "tajmeri.h"
  5.  
  6.  
  7. _FOSC(CSW_FSCM_OFF & XT_PLL4);
  8. _FWDT(WDT_OFF);
  9.  
  10.  
  11. //---------------------------------
  12. void portB_LED(unsigned char );
  13. unsigned int brojac_ms,stoperica,ms,sekund;
  14. unsigned char temp=0x0000;
  15. unsigned char pat=0x0001;
  16. unsigned char k=0;
  17. /*******************************************************************
  18. //funkcija za kasnjenje u milisekundama
  19. *********************************************************************/
  20. void Delay_ms (int vreme)//funkcija za kasnjenje u milisekundama
  21.     {
  22.         stoperica = 0;
  23.         while(stoperica < vreme);
  24.     }
  25.  
  26.  
  27.  
  28. void __attribute__ ((__interrupt__)) _T2Interrupt(void) // svakih 1ms
  29. {
  30.  
  31.         TMR2 =0;
  32.      ms=1;//fleg za milisekundu ili prekid;potrebno ga je samo resetovati u funkciji
  33.  
  34.     brojac_ms++;//brojac milisekundi
  35.     stoperica++;//brojac za funkciju Delay_ms
  36.  
  37.     if (brojac_ms==1000)//sek
  38.         {
  39.           brojac_ms=0;
  40.           sekund=1;//fleg za sekundu
  41.          }
  42.     IFS0bits.T2IF = 0;
  43.        
  44. }
  45.  
  46.    
  47.  
  48.  
  49. void main (void)
  50. {
  51.     ADPCFG=0xFFFF;
  52.  
  53.     TRISB=0x0000;
  54.  
  55. Init_T2();
  56. //  Init_T1();
  57. //  Init();
  58.  
  59.  
  60.     while(1)
  61.     {
  62.        
  63.         if(k<8)
  64.             portB_LED(1);
  65.         else
  66.             portB_LED(0);
  67.         //LATDbits.LATD0=~LATDbits.LATD0;  
  68.        
  69.            
  70.     }//while(1)
  71.  
  72.  
  73.  
  74. }//main
  75.  
  76. void portB_LED(unsigned char i)
  77. {
  78.     if(i==1){
  79.        
  80.         temp=temp | pat;
  81.         LATB=temp;
  82.         Delay_ms(200);
  83.         pat=pat<<1;
  84.         k++;
  85.         if(temp==0x00ff){
  86.             pat=0x0001;
  87.         }
  88.     }
  89.     else{
  90.         temp=temp>>1;
  91.         LATB=temp;
  92.         Delay_ms(200);
  93.         if(temp==0x0000){
  94.             k=0;
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment