Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. //**************************************************//
  2. //      Program: USART_RX_2.C                       //
  3. //      Author: Austin Schaller                     //
  4. //      Date: February 18st, 2011                   //
  5. //      Description: Utilizes PIC UART module       //
  6. //**************************************************//
  7.  
  8. #include <p18f1320.h>
  9. #include <delays.h>
  10. #include <usart.h>
  11. #pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON
  12.  
  13. void main()
  14. {
  15.     int i;
  16.     unsigned char data;
  17.     OSCCONbits.IRCF0=1;
  18.     OSCCONbits.IRCF1=1;
  19.     OSCCONbits.IRCF2=1;
  20.     while(!OSCCONbits.IOFS);
  21.     TRISB = 0x02;       // RB1 = USART Module I/O
  22.    
  23.     OpenUSART(  USART_BRGH_LOW,31 &         // 9600 Baud
  24.                 USART_ASYNCH_MODE &
  25.                 USART_CONT_RX
  26.              );
  27.    
  28.     while(1)
  29.     {
  30.         LATB = 0x00;
  31.         while(!PIR1bits.RCIF);      // Wait for RCIF to OVF
  32.         data = RCREG;       // Copy data into variable
  33.         PIR1bits.RCIF = 0;      // Clear OVF Flag
  34.        
  35.         if(data==0x0A)
  36.         {
  37.             for(i=0;i<4;i++)
  38.             {
  39.                 LATBbits.LATB0 = ~LATAbits.LATA0;
  40.                 Delay10KTCYx(25);
  41.             }
  42.         }
  43.    
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement