Advertisement
Mark2020H

Basic tutorial code for pic16F88 with xc8 mplab ide

May 17th, 2021 (edited)
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1. /* How to get the  pic16f88  to  operate on Port A */
  2. /* MD Harrington */
  3. /*  Done for the purposes of illustration to those new to  both C and embedded devices */
  4. /* using  updated  pic micro  8 bit micros  in response to Utube tutorial @ */
  5. /* https://www.youtube.com/watch?v=dPsuCt8JXjU&t=475s */
  6.  
  7.  
  8. /* Just about everything they  dont tell  you about in the above mentioned tutorial  
  9. You welcome to read my comments on this as well */
  10.  
  11.  
  12. // Header file functions.h
  13.  
  14. /* MD Harrington */
  15.  
  16. #pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
  17. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
  18. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
  19. #pragma config MCLRE = OFF      // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital I/O, MCLR internally tied to VDD)
  20. #pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
  21. #pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
  22. #pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
  23. #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
  24. #pragma config CCPMX = RB0      // CCP1 Pin Selection bit (CCP1 function on RB0)
  25. #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
  26.  
  27. // CONFIG2
  28. #pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
  29. #pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode disabled)
  30.  
  31. // #pragma config statements should precede project file includes.
  32. // Use project enums instead of #define for ON and OFF.
  33.  
  34. #include <xc.h>
  35.  
  36. /* Define clock  frequency  required  for delay  functions */
  37.  
  38.  
  39. #define _XTAL_FREQ 8000000
  40.  
  41.  
  42.  
  43. /*The main file */
  44.  
  45. /*
  46.  * File:   main.c
  47.  * Author: mark
  48.  *
  49.  * Created on 17 May 2021, 17:17
  50.  */
  51.  
  52. #include "functions.h"
  53.  
  54.  
  55. int main(int argc, char** argv) {
  56.    
  57.    
  58.    
  59.     TRISAbits.TRISA0 =  0; / THE PORT DIRECTION  BIT
  60.     ANSELbits.ANS0 = 0;    // digital out only   WE HAVE TO SET ANSEL REGISTER  TO  NOT ANALOGUE
  61.     OSCCON=0b01110100;    //osccon set to 8 mHZ  
  62.     PORTA=0x00 ;
  63.    
  64.         while (1){
  65.         PORTAbits.RA0 = 0 ;
  66.         __delay_ms(500); // 1 Second Delay
  67.         PORTAbits.RA0 = 1 ;
  68.         __delay_ms(500);
  69.  
  70.         }
  71.    
  72. }
  73.  
  74.  
  75. /* The compiled hex file
  76.  
  77. :020000040000FA
  78. :040000008A11FD2F35
  79. :100FA2008316031305101B1074308F008312031372
  80. :100FB20085018312031305100630F6001330F50085
  81. :100FC200AD30F400F40BE32FF50BE32FF60BE32F18
  82. :100FD200EA2F8312031305140630F6001330F500CE
  83. :100FE200AD30F400F40BF32FF50BF32FF60BF32FC8
  84. :0E0FF200FA2FDA2F8A11002883018A11D12FDD
  85. :04400E00183FFC3F1C
  86. :00000001FF
  87.  */
  88.  
  89.  
  90. /* LINKS  TO  DATA SHEET ON THIS DEVICE */
  91.  
  92.  
  93. /* https://static6.arrow.com/aropdfconversion/aef9dedd97cabb718583c4b2d2ebdad89a2ea9ca/6030487d.pdf */
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement