Genius Software to Burn pic16F628A

Thread Starter

new999

Joined Jan 18, 2016
12
Hello friends, I am trying to burn a code to pic16f628A using genius software but it shows error as configuration word error. The program works perfectly well on proteus, what might be the problem.
 

Thread Starter

new999

Joined Jan 18, 2016
12
No i did not set it. How do i go about it in mikroc for pic as i have used it to program the pic. I do not know of any other software
 

mcgyvr

Joined Oct 15, 2009
5,394
I don't use the software.. but my first suggestion is to read the manual..
Properly training yourself on any software is always a good idea.
 

JohnInTX

Joined Jun 26, 2012
4,787
I recovered the code from the .doc file. Always post code as plain text using code tags. A .doc file will not compile and further, many users won't open one because they can contain viruses.

You mentioned MikroC but the code is for XC8 - which is it?

You should be using the config bit setup facility in MPLABX (Window->PIC Memory Views->Configuration Bits.) Use the interactive window to set the config as necessary then click Generate Source Code to Output. Copy/paste the resulting text to your source. Click Clean and Build Main Project to generate the .HEX file with the config bits for the programmer. Don't build for debugging, build for Release. The config bits will be included with your .HEX file and the programmer should be happy. I don't know what a Genius programmer is but personally, I stick with Microchip stuff.

You are setting up your timer interrupt in the wrong order. Always fully configure the timer (or any other interrupt source for that matter) first then clear its interrupt flag. Only then should you enable the peripheral and global interrupts. Likewise, when setting up ports, you should set up the PORT values before the TRIS values.

Good luck.

C:
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT              PORTB
#define TRIS_DATA_PORT         TRISB

/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN   PORTAbits.RA0           /* PORT for RW */
#define TRIS_RW  TRISAbits.TRISA0        /* TRIS for RW */

#define RS_PIN   PORTAbits.RA1          /* PORT for RS */
#define TRIS_RS  TRISAbits.TRISA1        /* TRIS for RS */

#define E_PIN    PORTAbits.RA7         /* PORT for D  */
#define TRIS_E   TRISAbits.TRISA7        /* TRIS for E  */

// INCLUDES
#include <stdio.h>               // Including Standard Input / Outputlibrary
#include <stdlib.h>              // Including Standard library function
#include <xc.h>                  // Including XC8 compiler library
#include "my_xlcd.h"            // Including my custom LCD

// CONFIG
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC 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 = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON       // RA5/MCLR pin function select (RA5/MCLR pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOD Reset enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB4/PGM pin has PGM function, low-voltage programming enabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection off)
#pragma config CP = OFF         // Code Protection bits (Program memory code protection off)

// DEFINES
#define _XTAL_FREQ 4000000          // Telling the compiler, that we are using 4MHz
#define data PORTAbits.RA2          // Defining RA0 as datapin
#define data_dir TRISAbits.TRISA2   // Definig TRISA0 as dataport

// GLOBAL VARIABLES
char message1[] = "Temp = 00.0 c";
char message2[] = "RH   = 00.0 %";
unsigned short TOUT = 0, CheckSum, i;
unsigned short T_Byte1, T_Byte2, RH_Byte1, RH_Byte2;

// PROTOTYES
void init_XLCD(void);
void DelayFor18TCY(void);
void DelayPORXLCD(void);
void DelayXLCD(void);
void Delay10KTCYx(unsigned char);
void StartSignal(void);
unsigned short ReadByte();
unsigned short CheckResponse();

// FUNCTIONS
void init_XLCD(void){
    OpenXLCD(FOUR_BIT & LINES_5X7);     // Sets 4-bit & 5x7 charachters
    while(BusyXLCD());                  // Checks if LCD is busy
    WriteCmdXLCD(0x06);                 // Moves cursor right
    WriteCmdXLCD(0x0C);                 // Display on, cursor off
}

void DelayFor18TCY(void){               // as it says in the XLCD.H file
    NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
    NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
    return;
}

void DelayPORXLCD(void){               // as it says in the XLCD.H file
    __delay_ms(15);
}

void DelayXLCD(void){                 // as it says in the XLCD.H file
    __delay_ms(5);
}

void Delay10KTCYx(unsigned char){     // as it says in the XLCD.H file
    __delay_ms(10);
}
void StartSignal(){
    data_dir = 0;       // Sets TRISA2 to output
    data = 0;           // Set RA2 to LOW
    __delay_ms(18);     // Waits for 18 ms
    data = 1;           // Sets RA2 HIGH
    __delay_us(20);     // Waits for 20 ms
    data_dir = 1;       // Sets TRISA2 to input
}

unsigned short ReadByte(){
    unsigned short num = 0, t;
    data_dir = 1;                       // Sets TRISA2 to input
    for (i=0;i<8;i++){                  // Start loop
        while(!data);                   // When data is not valid
        TMR2 = 0;                       // Sets TMR2 to 0
        T2CONbits.TMR2ON = 1;           // Start TMR2 from 0 when a low to high data pulse
        while(data);                    // is detected, and wait until it falls low again
        T2CONbits.TMR2ON = 0;           // Stop the TMR2 when the data pulse falls low
        if(TMR2>40) num |= 1 << (7-i);  // If time > 40us, data is 1
        }
    return num;                         // Return 8-bit = 1-byte
}
unsigned short CheckResponse(){
    TOUT = 0;
    TMR2 = 0;
    T2CONbits.TMR2ON = 1;       // Turn on TMR2
    while(!data && !TOUT);      // While NOT data and NOT TOUT
    if (TOUT) return 0;         // Return 0 => OK
    else {
        TMR2 = 0;               // Disable Timer 2
        while(data && !TOUT);   // While data and NOT TOUT
        if(TOUT) return 0;      // If Tout = 1 then return 0 => OK
        else {
            T2CONbits.TMR2ON = 0;   // Turn off TMR2
            return 1;               // Return 1 => NOT OK
        }
    }
}
void interrupt tc_int(void){
    if(PIR1bits.TMR2IF){            // If TMR2 to PR2 match Interrupt Flag
        TOUT = 1;
        T2CONbits.TMR2ON = 0;       // Stop timer
        PIR1bits.TMR2IF = 0;        // Clear TMR0 interrupt flag
    }
}

int main(int argc, char** argv) {
    unsigned short check;
    TRISB = 0b00000000;         // TRISB output
    PORTB = 0b00000000;         // PORTB low
    TRISA = 0b00000001;         // TRISA output
    PORTA = 0b00000000;         // PORTA low

    CMCON = 0x07;               // Comparators off

    // TIMER
    INTCONbits.GIE = 1;         // Enable global interrupt
    INTCONbits.PEIE = 1;        // Enable peripheral interrupt
    PIE1bits.TMR2IE = 1;        // Enable Timer2 interrupt
    T2CON = 0;                  // Prescaler 1:1 and Timer2 is off initially
    PIR1bits.TMR2IF = 0;        // Clear TMR INT flag bit
    TMR2 = 0;

    init_XLCD();                // Initialize the LCD
    putrsXLCD("  Hello World.");    // Welcome text
    SetDDRamAddr(0x40);             // Move cursor to line 2
    putrsXLCD("  I'm alive.");
    __delay_ms(250);
    do {
        __delay_ms(1000);
        StartSignal();              // Send the Startsignal
        check = CheckResponse();    // Assign check with 0 = OK, or 1 = NOT OK
        if(!check) {                // OK check = 1 => NOT OK
            WriteCmdXLCD(0x01);     // Clear screen, set cursor in 0,0
            putrsXLCD("No response.");  // Write error message
            SetDDRamAddr(0x40); 
            putrsXLCD("Please check.");
            }
        else {                      // IF chack = 0 => OK

        RH_Byte1 = ReadByte();      // Read first byte
        RH_Byte2 = ReadByte();      // Read second byte
        T_Byte1 = ReadByte();       // Read third byte
        T_Byte2 = ReadByte();       // Read fourth byte
        CheckSum = ReadByte();      // Read checksum
        // Checks if all bytes is equal to the checksum
        if (CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF))
        {
            message1[7] = T_Byte1/10 + 48;      // Extract the tens place
            message1[8] = T_Byte1 + 48;      // Extract the ones place
            message1[10]= T_Byte2/10 + 48;      // Extract the decimal
            message1[11] = 223;                 // ASCII code for degree symbol  
            message2[7] = RH_Byte1/10 + 48;     // Extract the tens place
            message2[8] = RH_Byte1 + 48;     // Extract the ones place
            message2[10] = RH_Byte2/10 + 48;    // Extract the decimal

            WriteCmdXLCD(0x01);
            putrsXLCD(message1);    // Write the temp to LCD
            SetDDRamAddr(0x40);
            putrsXLCD(message2);    // Write the humidity to LCD
        }
        else {                      // Checksum is not correct
            WriteCmdXLCD(0x01);
            putrsXLCD("Checksum error!");
            SetDDRamAddr(0x40);
            putrsXLCD("Please wait.");
        }
        }
    } while (1);    // Do it forever.
}
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Hello friends, I am trying to burn a code to pic16f628A using genius software but it shows error as configuration word error. The program works perfectly well on proteus, what might be the problem.
Are you going to tell us the error? Or do you want to keep that a secret?
 
Top