Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.32 KB | None | 0 0
  1. #define _XTAL_FREQ 32000000
  2.  
  3. // PIC16F18875 Configuration Bit Settings
  4.  
  5. // 'C' source line config statements
  6.  
  7. // CONFIG1
  8. #pragma config FEXTOSC = OFF      // External Oscillator mode selection bits (EC above 8MHz; PFM set to high power)
  9. #pragma config RSTOSC = HFINT32  // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)
  10. #pragma config CLKOUTEN = OFF    // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
  11. #pragma config CSWEN = ON        // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
  12. #pragma config FCMEN = ON        // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
  13.  
  14. // CONFIG2
  15. #pragma config MCLRE = ON        // Master Clear Enable bit (MCLR pin is Master Clear function)
  16. #pragma config PWRTE = OFF       // Power-up Timer Enable bit (PWRT disabled)
  17. #pragma config LPBOREN = OFF     // Low-Power BOR enable bit (ULPBOR disabled)
  18. #pragma config BOREN = OFF        // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
  19. #pragma config BORV = LO         // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
  20. #pragma config ZCD = OFF         // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
  21. #pragma config PPS1WAY = ON      // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
  22. #pragma config STVREN = ON       // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
  23.  
  24. // CONFIG3
  25. #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
  26. #pragma config WDTE = OFF        // WDT operating mode (WDT enabled regardless of sleep; SWDTEN ignored)
  27. #pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits (window always open (100%); software control; keyed access not required)
  28. #pragma config WDTCCS = SC       // WDT input clock selector (Software Control)
  29.  
  30. // CONFIG4
  31. #pragma config WRT = OFF         // UserNVM self-write protection bits (Write protection off)
  32. #pragma config SCANE = available // Scanner Enable bit (Scanner module is available for use)
  33. #pragma config LVP = ON          // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
  34.  
  35. // CONFIG5
  36. #pragma config CP = OFF          // UserNVM Program memory code protection bit (Program Memory code protection disabled)
  37. #pragma config CPD = OFF         // DataNVM code protection bit (Data EEPROM code protection disabled)
  38.  
  39. // #pragma config statements should precede project file includes.
  40. // Use project enums instead of #define for ON and OFF.
  41.  
  42. #include <xc.h>
  43.  
  44. void displayNumber(int);
  45. void display();
  46.  
  47. void main(void)
  48. {    
  49.     TRISA = 0b00000000;
  50.     TRISB = 0b00000000; //Register to display data(for number on VFD tube) on display bus (7 bit)
  51.    
  52.     while(1){
  53.         displayNumber(1);
  54.         //display();        
  55.     }
  56.    
  57.     return;             //Restart program
  58. }
  59.  
  60. void display(){
  61.         //8888888888888888888888888888888888
  62.         displayNumber(2);
  63.        
  64.         LATA0 = 1;
  65.         __delay_ms(5);
  66.         LATA0 = 0;
  67.         //8888888888888888888888888888888888
  68.         displayNumber(5);
  69.         LATA1 = 1;
  70.         __delay_ms(5);
  71.         LATA1 = 0;
  72.         //8888888888888888888888888888888888
  73.         displayNumber(7);
  74.         LATA2 = 1;
  75.         __delay_ms(5);
  76.         LATA2 = 0;
  77.         //8888888888888888888888888888888888
  78.         displayNumber(1);
  79.         LATA3 = 1;
  80.         __delay_ms(5);
  81.         LATA3 = 0;
  82.         //8888888888888888888888888888888888
  83. }
  84.  
  85. void displayNumber(int display){
  86.    
  87.     if(display == 1){
  88.         LATB0 = 0;
  89.         LATB1 = 0;
  90.         LATB2 = 0;
  91.         LATB3 = 1;
  92.         LATB4 = 1;
  93.         LATB5 = 0;
  94.         LATA4 = 0;
  95.     }else if(display == 2){
  96.         LATB0 = 0;
  97.         LATB1 = 1;
  98.         LATB2 = 1;
  99.         LATB3 = 0;
  100.         LATB4 = 1;
  101.         LATB5 = 1;
  102.         LATB6 = 1;
  103.     }else if(display == 3){
  104.         LATC0 = 0;
  105.         LATC1 = 0;
  106.         LATC2 = 1;
  107.         LATC3 = 1;
  108.         LATC4 = 1;
  109.         LATC5 = 1;
  110.         LATC6 = 1;
  111.     }else if(display == 4){
  112.         LATC0 = 1;
  113.         LATC1 = 0;
  114.         LATC2 = 0;
  115.         LATC3 = 1;
  116.         LATC4 = 1;
  117.         LATC5 = 0;
  118.         LATC6 = 1;
  119.     }else if(display == 5){
  120.         LATC0 = 1;
  121.         LATC1 = 0;
  122.         LATC2 = 1;
  123.         LATC3 = 1;
  124.         LATC4 = 0;
  125.         LATC5 = 1;
  126.         LATC6 = 1;
  127.     }else if(display == 6){
  128.         LATC0 = 1;
  129.         LATC1 = 1;
  130.         LATC2 = 1;
  131.         LATC3 = 1;
  132.         LATC4 = 0;
  133.         LATC5 = 1;
  134.         LATC6 = 1;
  135.     }else if(display == 7){
  136.         LATC0 = 0;
  137.         LATC1 = 0;
  138.         LATC2 = 0;
  139.         LATC3 = 1;
  140.         LATC4 = 1;
  141.         LATC5 = 1;
  142.         LATC6 = 0;
  143.     }else if(display == 8){
  144.         LATC0 = 1;
  145.         LATC1 = 1;
  146.         LATC2 = 1;
  147.         LATC3 = 1;
  148.         LATC4 = 1;
  149.         LATC5 = 1;
  150.         LATC6 = 1;
  151.     }else if(display == 9){
  152.         LATC0 = 1;
  153.         LATC1 = 0;
  154.         LATC2 = 1;
  155.         LATC3 = 1;
  156.         LATC4 = 1;
  157.         LATC5 = 1;
  158.         LATC6 = 1;
  159.     }else if(display == 0){
  160.         LATC0 = 1;
  161.         LATC1 = 1;
  162.         LATC2 = 1;
  163.         LATC3 = 1;
  164.         LATC4 = 1;
  165.         LATC5 = 1;
  166.         LATC6 = 0;
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement