Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XTAL_FREQ 32000000
- // PIC16F18875 Configuration Bit Settings
- // 'C' source line config statements
- // CONFIG1
- #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (EC above 8MHz; PFM set to high power)
- #pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)
- #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
- #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
- #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
- // CONFIG2
- #pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
- #pragma config BOREN = OFF // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
- #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)
- #pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
- #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
- #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
- // CONFIG3
- #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
- #pragma config WDTE = OFF // WDT operating mode (WDT enabled regardless of sleep; SWDTEN ignored)
- #pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits (window always open (100%); software control; keyed access not required)
- #pragma config WDTCCS = SC // WDT input clock selector (Software Control)
- // CONFIG4
- #pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off)
- #pragma config SCANE = available // Scanner Enable bit (Scanner module is available for use)
- #pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
- // CONFIG5
- #pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled)
- #pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled)
- // #pragma config statements should precede project file includes.
- // Use project enums instead of #define for ON and OFF.
- #include <xc.h>
- void displayNumber(int);
- void display();
- void main(void)
- {
- TRISA = 0b00000000;
- TRISB = 0b00000000; //Register to display data(for number on VFD tube) on display bus (7 bit)
- while(1){
- displayNumber(1);
- //display();
- }
- return; //Restart program
- }
- void display(){
- //8888888888888888888888888888888888
- displayNumber(2);
- LATA0 = 1;
- __delay_ms(5);
- LATA0 = 0;
- //8888888888888888888888888888888888
- displayNumber(5);
- LATA1 = 1;
- __delay_ms(5);
- LATA1 = 0;
- //8888888888888888888888888888888888
- displayNumber(7);
- LATA2 = 1;
- __delay_ms(5);
- LATA2 = 0;
- //8888888888888888888888888888888888
- displayNumber(1);
- LATA3 = 1;
- __delay_ms(5);
- LATA3 = 0;
- //8888888888888888888888888888888888
- }
- void displayNumber(int display){
- if(display == 1){
- LATB0 = 0;
- LATB1 = 0;
- LATB2 = 0;
- LATB3 = 1;
- LATB4 = 1;
- LATB5 = 0;
- LATA4 = 0;
- }else if(display == 2){
- LATB0 = 0;
- LATB1 = 1;
- LATB2 = 1;
- LATB3 = 0;
- LATB4 = 1;
- LATB5 = 1;
- LATB6 = 1;
- }else if(display == 3){
- LATC0 = 0;
- LATC1 = 0;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 1;
- LATC6 = 1;
- }else if(display == 4){
- LATC0 = 1;
- LATC1 = 0;
- LATC2 = 0;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 0;
- LATC6 = 1;
- }else if(display == 5){
- LATC0 = 1;
- LATC1 = 0;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 0;
- LATC5 = 1;
- LATC6 = 1;
- }else if(display == 6){
- LATC0 = 1;
- LATC1 = 1;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 0;
- LATC5 = 1;
- LATC6 = 1;
- }else if(display == 7){
- LATC0 = 0;
- LATC1 = 0;
- LATC2 = 0;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 1;
- LATC6 = 0;
- }else if(display == 8){
- LATC0 = 1;
- LATC1 = 1;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 1;
- LATC6 = 1;
- }else if(display == 9){
- LATC0 = 1;
- LATC1 = 0;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 1;
- LATC6 = 1;
- }else if(display == 0){
- LATC0 = 1;
- LATC1 = 1;
- LATC2 = 1;
- LATC3 = 1;
- LATC4 = 1;
- LATC5 = 1;
- LATC6 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement