Advertisement
Guest User

Proteus PRAC5

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <xc.h>
  2.  
  3. //Codi 1
  4. void main(void) {
  5.     //Config
  6.    
  7.     //Set as digital port
  8.     ANSELA = 0x00;
  9.     ANSELB = 0x00;
  10.    
  11.     //Set RA0 as output
  12.     //TRISA = 0x00;
  13.     TRISAbits.RA0 = 0;
  14.    
  15.     //Set RB0 as input
  16.     TRISBbits.RA0 = 1;
  17.    
  18.     while (1) {
  19.         PORTAbits.RA0 = PORTBbits.RB0;
  20.     }
  21. }
  22.  
  23.  
  24. //Codi 2
  25. int apretat = 0;
  26.  
  27. void main2(void) {
  28.     //Config
  29.    
  30.     //Set as digital port
  31.     ANSELA = 0x00;
  32.     ANSELB = 0x00;
  33.    
  34.     //Set RA0 as output
  35.     //TRISA = 0x00;
  36.     TRISAbits.RA0 = 0;
  37.    
  38.     //Set RB0 as input
  39.     TRISBbits.RA0 = 1;
  40.    
  41.     while (1) {
  42.         if (!PORTBbits.RB0) {
  43.             if (apretat) {
  44.                 apretat = 0;
  45.                 PORTAbits.RA0 = !PORTAbits.RA0;
  46.             }
  47.         }
  48.         else {
  49.             apretat = 1;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement