T
treez
Guest
Hello,
Please could you help see if this C code has got any faults in it? It builds OK, but I wonder if it will work?
It uses the PIC16F18856. It just puts it through its paces. We have a new board arriving on Friday, and we must get it working by Friday to go to a show and be programmed by the software engineer.
The software engineer will kill us if the board isnt good....so we want to get the micro to do some basic stuff like taking pins high and low.....to see if the board's ok.
Please could you help see if this C code has got any faults in it? It builds OK, but I wonder if it will work?
It uses the PIC16F18856. It just puts it through its paces. We have a new board arriving on Friday, and we must get it working by Friday to go to a show and be programmed by the software engineer.
The software engineer will kill us if the board isnt good....so we want to get the micro to do some basic stuff like taking pins high and low.....to see if the board's ok.
Code:
//TEST CODE FOR "590P" Board
//This just exercises the basic features of the board
//so that we can see that the board is good.
//PIC16F18856
//XC8 compiler
//MPLAB X V3.61
//date 27 oct 2017
// PIC16F18856 Configuration Bit Settings
//
// 'C' source line config statements
// CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = OFF // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled)
// CONFIG2
#pragma config MCLRE = OFF // Master Clear Enable bit (MCLR pin function is port defined function)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON // 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 = OFF // Peripheral Pin Select one-way control (The PPSLOCK bit can be set and cleared repeatedly by software)
#pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will not 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 Disabled, SWDTEN is 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 = not_available// Scanner Enable bit (Scanner module is not available for use)
#pragma config LVP = OFF // Low Voltage Programming Enable bit (High Voltage on MCLR/Vpp must be used for programming)
// 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>
#include <stdint.h>
#define _XTAL_FREQ 4000000
uint16_t count;
uint16_t count1;
uint16_t count2;
void main(void) {
//Setup ports
TRISA = 0x90; //
TRISB = 0x3A; //
TRISC = 0x15; //
ANSELA = 0x10; //
ANSELB = 0x00;
ANSELC = 0x05;
WPUA = 0x00;
ODCONA = 0x00;
SLRCONA = 0x00;
INLVLA = 0x00; //ST?
CCDPA = 0x00;
CCDNA = 0x00;
WPUB = 0x00;
ODCONB = 0x00;
SLRCONB = 0x00;
INLVLB = 0x00; //ST?
CCDPB = 0x00;
CCDNB = 0x00;
WPUC = 0x00;
ODCONC = 0x00;
SLRCONC = 0x00;
INLVLC = 0x00; //ST?
CCDPC = 0x00;
CCDNC = 0x00;
INTCON = 0x00;
CM1CON0 = 0x00;
CM1CON1 = 0x00;
CM2CON0 = 0x00;
CM2CON1 = 0x00;
PWM6CON = 0x00;
PWM7CON = 0x00;
ZCDCON = 0x00;
//Initialize ports
LATAbits.LATA0 = 0; //HI switchs ON 24v rail to ext
LATAbits.LATA1 = 0; //hi switchs off DALI Buck
LATAbits.LATA2 = 1; //pwm dimming
LATAbits.LATA3 = 0; //nc
//LATAbits.LATA4 = 0; //ADC temperature
LATAbits.LATA5 = 0; //nc
LATAbits.LATA6 = 1; //nc
//LATAbits.LATA7 = 0; //low means undervoltage
LATBbits.LATB0 = 0; //nc
//LATBbits.LATB1 = 0; //digi id
LATBbits.LATB2 = 0; //dali tx
//LATBbits.LATB3 = 0; //dali rx
//LATBbits.LATB4 = 0; //input from EH pin of st25dv04k
//LATBbits.LATB5 = 0; //input from st25dv04k gpo
LATBbits.LATB6 = 0; //icspclk
LATBbits.LATB7 = 0; //icspdat
//LATCbits.LATC0 = 0; //ADC from Iout
LATCbits.LATC1 = 0; //HI TURNS OFF LED DRIVER
//LATCbits.LATC2 = 0; //ADC from Vout
LATCbits.LATC3 = 0; //OUTPUT TO CLK OF ST25DV04K
//LATCbits.LATC4 = 0; //input from SDA of ST25DV04K
LATCbits.LATC5 = 0; //NC
LATCbits.LATC6 = 0; //OUTPUT TO TEST PIN
LATCbits.LATC7 = 0; //OUTPUT TO TEST PIN
//DO PWM dimming
//--------------------------------------------------------
here:
count1 = 0;
while (1) {
//Do PWM dimming
count = 0;
while(1) {
LATAbits.LATA2 = 0;
__delay_us(100);
LATAbits.LATA2 = 1;
__delay_us(900);
count = count + 1;
if (count >1000) {break;}
}
//Do PWM dimming
count = 0;
while(1) {
LATAbits.LATA2 = 0;
__delay_us(300);
LATAbits.LATA2 = 1;
__delay_us(700);
count = count + 1;
if (count >1000) {break;}
}
count1 = count1 + 1;
if (count1 >1000) {break;}
}
//-----------------------------------------------------------
// set leds on full power
LATAbits.LATA2 = 0;
//SWITCH ON DALI BUCK....
LATAbits.LATA1 = 0;
//DO SOME TRANSMITTING OF DALI
//--------------------------------------------------------
count1 = 0;
while (1) {
//Do PWM dimming
count = 0;
while(1) {
LATBbits.LATB2 = 0;
__delay_us(433);
LATBbits.LATB2 = 1;
__delay_us(433);
count = count + 1;
if (count >1000) {break;}
}
//Do PWM dimming
count = 0;
while(1) {
LATBbits.LATB2 = 0;
__delay_us(433);
LATBbits.LATB2 = 1;
__delay_us(433);
count = count + 1;
if (count >1000) {break;}
}
count1 = count1 + 1;
if (count1 >1000) {break;}
}
LATBbits.LATB2 = 0; //TURN OFF dali NPN
//-----------------------------------------------------------
//Now Turn LEDs on and off
//--------------------------------------------------------
count1 = 0;
while (1) {
//Do PWM dimming
count = 0;
while(1) {
LATCbits.LATC1 = 0;
__delay_ms(433);
LATCbits.LATC1 = 1;
__delay_ms(433);
count = count + 1;
if (count >10) {break;}
}
//Do PWM dimming
count = 0;
while(1) {
LATCbits.LATC1 = 0;
__delay_ms(433);
LATCbits.LATC1 = 1;
__delay_ms(433);
count = count + 1;
if (count >10) {break;}
}
count1 = count1 + 1;
if (count1 >10) {break;}
}
//-----------------------------------------------------------
goto here;
return;
}