PIC16F628A HI-TECH C Compiler while loop issue

Thread Starter

odm4286

Joined Sep 20, 2009
265
Well, this might sound like a crazy problem but hopefully someone can help me out. So I'm writting code to interface with an XBEE chip and I couldn't get it to work. So as a bit of a sanity check I decided to turn on a LED(RA1) just to make sure the chip was actually running. To my complete surprise the LED will NOT turn on during the while loop, it seems the only code thats ever run is what is outside the while loop, is this a special thing with the HI-TECH compiler? First time I've used it so im not sure, heres my source.

C:
/* 
 * File:   main.c
 * Author: user
 *
 * Created on September 27, 2015, 10:05 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include <pic16f628a.h>
#include <htc.h>

__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & BOREN_ON & LVP_ON & CPD_OFF & CP_OFF);

#define ONESEC 125000


/*
 * 
 */
int main(int argc, char** argv) {

     char id[] = {'a','b','c','d'};
     // Pin and interrupt configuration
     TRISB = 0x7;                         // all outputs except, RB0 - RB2
     TRISA = 0x0;                         // all outputs
     RA1 = 1;
     INTCON = 0x10;                       // enabling INT(RB0) external interrupt, clearing flag
     INTEDG = 1;                          // Configures RBO to interrupt on rising edge

     RCIE = 1;                            // Rx interrupt enabled, interrupt when receiving data
     RCIF = 0;                            // clearing flag
     
     // USART configuration - hopefully this works correctly with xbee
     BRGH = 1;                            // highspeed selected, desired 9600 actual 9615
     SPBRG = 25;                          // baud rate = Fosc/16(SPBRG+1)
     CSRC = 0;                            // Aynchronous mode, internal BRG
     TXEN = 1;                            // Transmit enable
     SYNC = 0;                            // Asynchronous mode.
     SPEN = 1;                            // Enable serial comm
     CREN = 1;                            // Continuous receive

     // timer1 setup 
     T1CONbits.T1CKPS = 0b11;             // 1:8 prescaler 125k = one second
     TMR1ON = 1;                          // turn the timer on
     while(1)
     {
           
             // transmit test...
             //TXREG = id[0]; 
            // anything in here doesn't work for some reason

           
     }
    return (EXIT_SUCCESS);
}
 

dannyf

Joined Sep 13, 2015
2,197
To my complete surprise the LED will NOT turn on during the while loop,
Read the datasheet carefully, particularly the portion about the gpio pins. Pay extreme attention to the registers that you will need to take care of, and compare your code to the examples.

This is where mos PIC programmers are taken initially.

You can simulate your code in mplab to see what's going on.
 

Thread Starter

odm4286

Joined Sep 20, 2009
265
Thanks for the tip, but I've done that. The code works fine if I do stuff OUTSIDE the while loop, which is so strange to me
 

Thread Starter

odm4286

Joined Sep 20, 2009
265
Seems to work now, I must have had something wired in correctly or a bad connection o_O good thing is it works now
 
Top