T
treez
Guest
Hello,
Our short C code builds but won’t run properly. (please find it attached)
(the output RB5, never goes high, even though the pulse train is definitely getting to the input pin RA2)
It is written in XC8 C in MPLAB.
The microcontroller is PIC16F627A
Do you know why it doesnt work as it should?
Our short C code builds but won’t run properly. (please find it attached)
(the output RB5, never goes high, even though the pulse train is definitely getting to the input pin RA2)
It is written in XC8 C in MPLAB.
The microcontroller is PIC16F627A
Do you know why it doesnt work as it should?
Code:
//This code simply has an input "looking"
//at a train of pulses.
//When one of the pulses goes low, a delay is done....
//and then an output is taken high.
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 4000000
#include <xc.h>
#include <stdint.h>
uint8_t count;
uint8_t count1;
uint8_t count2;
void main(void) {
//Setup ports
// TRISA = 0b 1011 1100; //ADC INS
// TRISB = 0b 00000001; //ZCD & DALIRX..really 0x09
TRISA = 0xBC;
TRISB = 0x01;
RA0 = 0; //NC
RA1 = 0; //NC
//RA2 = 0; //ZERO X ..input
//RA3 = 0; //on/off ..input
//RA4 = 0; //select zapper ..input
//RA5 = 0; //RA5 ..MCLR ..input
RA6 = 0; //RA6 ..LED failure ..output
//RA7 = 0; //failure ..input
//RB0 = 0; //SELECT OAMP ..INPUT
RB1 = 0; //LED ..ZAPPER ..OUTPUT
RB2 = 0; //LED OAMP ..OUTPUT
RB3 = 0; //NC ..OUTPUT
RB4 = 0; //ZAPPER SWITCH ..OUTPUT
RB5 = 0; //AC SWITCH ..OUTPUT
RB6 = 0; //PGC ...OUTPUT
RB7 = 0; //PGD ..OUTPUT
INTCON = 0x00;
//OPTION_REG = 0b 10000111
OPTION_REG = 0x87;
//VRCON = 0b00;
VRCON = 0x00;
CMCON = 0x07;
while (RA2 == 0);
while (RA2 ==1);
//At this point the pulse has just gone low
__delay_ms(3); //delay to get to the mains peak
__delay_us(600);
RB5 = 1;
__delay_ms(1);
RB5 = 0;
while(1){;}
return;
}