Genius Software to Burn pic16F628A

Discussion in 'Embedded Systems and Microcontrollers' started by new999, Feb 29, 2016.

  1. new999

    Thread Starter New Member

    Jan 18, 2016
    12
    0
    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.
     
  2. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    Did you set your configuration words for setting the fuses?
     
  3. new999

    Thread Starter New Member

    Jan 18, 2016
    12
    0
    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
     
  4. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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.
     
  5. new999

    Thread Starter New Member

    Jan 18, 2016
    12
    0
    This is made in MPlab however there is some error. pl help me correct it and send the hex file.
     
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
  7. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    I can't open your file. Why don't you use the code-tags in the editor's menu and show us your code?
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    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.

    Code (C):
    1. /* DATA_PORT defines the port to which the LCD data lines are connected */
    2. #define DATA_PORT              PORTB
    3. #define TRIS_DATA_PORT         TRISB
    4.  
    5. /* CTRL_PORT defines the port where the control lines are connected.
    6. * These are just samples, change to match your application.
    7. */
    8. #define RW_PIN   PORTAbits.RA0           /* PORT for RW */
    9. #define TRIS_RW  TRISAbits.TRISA0        /* TRIS for RW */
    10.  
    11. #define RS_PIN   PORTAbits.RA1          /* PORT for RS */
    12. #define TRIS_RS  TRISAbits.TRISA1        /* TRIS for RS */
    13.  
    14. #define E_PIN    PORTAbits.RA7         /* PORT for D  */
    15. #define TRIS_E   TRISAbits.TRISA7        /* TRIS for E  */
    16.  
    17. // INCLUDES
    18. #include <stdio.h>               // Including Standard Input / Outputlibrary
    19. #include <stdlib.h>              // Including Standard library function
    20. #include <xc.h>                  // Including XC8 compiler library
    21. #include "my_xlcd.h"            // Including my custom LCD
    22.  
    23. // CONFIG
    24. #pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
    25.  
    26. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
    27. #pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
    28. #pragma config MCLRE = ON       // RA5/MCLR pin function select (RA5/MCLR pin function is MCLR)
    29. #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOD Reset enabled)
    30. #pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB4/PGM pin has PGM function, low-voltage programming enabled)
    31. #pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection off)
    32. #pragma config CP = OFF         // Code Protection bits (Program memory code protection off)
    33.  
    34. // DEFINES
    35. #define _XTAL_FREQ 4000000          // Telling the compiler, that we are using 4MHz
    36. #define data PORTAbits.RA2          // Defining RA0 as datapin
    37. #define data_dir TRISAbits.TRISA2   // Definig TRISA0 as dataport
    38.  
    39. // GLOBAL VARIABLES
    40. char message1[] = "Temp = 00.0 c";
    41. char message2[] = "RH   = 00.0 %";
    42. unsigned short TOUT = 0, CheckSum, i;
    43. unsigned short T_Byte1, T_Byte2, RH_Byte1, RH_Byte2;
    44.  
    45. // PROTOTYES
    46. void init_XLCD(void);
    47. void DelayFor18TCY(void);
    48. void DelayPORXLCD(void);
    49. void DelayXLCD(void);
    50. void Delay10KTCYx(unsigned char);
    51. void StartSignal(void);
    52. unsigned short ReadByte();
    53. unsigned short CheckResponse();
    54.  
    55. // FUNCTIONS
    56. void init_XLCD(void){
    57.     OpenXLCD(FOUR_BIT & LINES_5X7);     // Sets 4-bit & 5x7 charachters
    58.     while(BusyXLCD());                  // Checks if LCD is busy
    59.     WriteCmdXLCD(0x06);                 // Moves cursor right
    60.     WriteCmdXLCD(0x0C);                 // Display on, cursor off
    61. }
    62.  
    63. void DelayFor18TCY(void){               // as it says in the XLCD.H file
    64.     NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
    65.     NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
    66.     return;
    67. }
    68.  
    69. void DelayPORXLCD(void){               // as it says in the XLCD.H file
    70.     __delay_ms(15);
    71. }
    72.  
    73. void DelayXLCD(void){                 // as it says in the XLCD.H file
    74.     __delay_ms(5);
    75. }
    76.  
    77. void Delay10KTCYx(unsigned char){     // as it says in the XLCD.H file
    78.     __delay_ms(10);
    79. }
    80. void StartSignal(){
    81.     data_dir = 0;       // Sets TRISA2 to output
    82.     data = 0;           // Set RA2 to LOW
    83.     __delay_ms(18);     // Waits for 18 ms
    84.     data = 1;           // Sets RA2 HIGH
    85.     __delay_us(20);     // Waits for 20 ms
    86.     data_dir = 1;       // Sets TRISA2 to input
    87. }
    88.  
    89. unsigned short ReadByte(){
    90.     unsigned short num = 0, t;
    91.     data_dir = 1;                       // Sets TRISA2 to input
    92.     for (i=0;i<8;i++){                  // Start loop
    93.         while(!data);                   // When data is not valid
    94.         TMR2 = 0;                       // Sets TMR2 to 0
    95.         T2CONbits.TMR2ON = 1;           // Start TMR2 from 0 when a low to high data pulse
    96.         while(data);                    // is detected, and wait until it falls low again
    97.         T2CONbits.TMR2ON = 0;           // Stop the TMR2 when the data pulse falls low
    98.         if(TMR2>40) num |= 1 << (7-i);  // If time > 40us, data is 1
    99.         }
    100.     return num;                         // Return 8-bit = 1-byte
    101. }
    102. unsigned short CheckResponse(){
    103.     TOUT = 0;
    104.     TMR2 = 0;
    105.     T2CONbits.TMR2ON = 1;       // Turn on TMR2
    106.     while(!data && !TOUT);      // While NOT data and NOT TOUT
    107.     if (TOUT) return 0;         // Return 0 => OK
    108.     else {
    109.         TMR2 = 0;               // Disable Timer 2
    110.         while(data && !TOUT);   // While data and NOT TOUT
    111.         if(TOUT) return 0;      // If Tout = 1 then return 0 => OK
    112.         else {
    113.             T2CONbits.TMR2ON = 0;   // Turn off TMR2
    114.             return 1;               // Return 1 => NOT OK
    115.         }
    116.     }
    117. }
    118. void interrupt tc_int(void){
    119.     if(PIR1bits.TMR2IF){            // If TMR2 to PR2 match Interrupt Flag
    120.         TOUT = 1;
    121.         T2CONbits.TMR2ON = 0;       // Stop timer
    122.         PIR1bits.TMR2IF = 0;        // Clear TMR0 interrupt flag
    123.     }
    124. }
    125.  
    126. int main(int argc, char** argv) {
    127.     unsigned short check;
    128.     TRISB = 0b00000000;         // TRISB output
    129.     PORTB = 0b00000000;         // PORTB low
    130.     TRISA = 0b00000001;         // TRISA output
    131.     PORTA = 0b00000000;         // PORTA low
    132.  
    133.     CMCON = 0x07;               // Comparators off
    134.  
    135.     // TIMER
    136.     INTCONbits.GIE = 1;         // Enable global interrupt
    137.     INTCONbits.PEIE = 1;        // Enable peripheral interrupt
    138.     PIE1bits.TMR2IE = 1;        // Enable Timer2 interrupt
    139.     T2CON = 0;                  // Prescaler 1:1 and Timer2 is off initially
    140.     PIR1bits.TMR2IF = 0;        // Clear TMR INT flag bit
    141.     TMR2 = 0;
    142.  
    143.     init_XLCD();                // Initialize the LCD
    144.     putrsXLCD("  Hello World.");    // Welcome text
    145.     SetDDRamAddr(0x40);             // Move cursor to line 2
    146.     putrsXLCD("  I'm alive.");
    147.     __delay_ms(250);
    148.     do {
    149.         __delay_ms(1000);
    150.         StartSignal();              // Send the Startsignal
    151.         check = CheckResponse();    // Assign check with 0 = OK, or 1 = NOT OK
    152.         if(!check) {                // OK check = 1 => NOT OK
    153.             WriteCmdXLCD(0x01);     // Clear screen, set cursor in 0,0
    154.             putrsXLCD("No response.");  // Write error message
    155.             SetDDRamAddr(0x40);
    156.             putrsXLCD("Please check.");
    157.             }
    158.         else {                      // IF chack = 0 => OK
    159.  
    160.         RH_Byte1 = ReadByte();      // Read first byte
    161.         RH_Byte2 = ReadByte();      // Read second byte
    162.         T_Byte1 = ReadByte();       // Read third byte
    163.         T_Byte2 = ReadByte();       // Read fourth byte
    164.         CheckSum = ReadByte();      // Read checksum
    165.         // Checks if all bytes is equal to the checksum
    166.         if (CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF))
    167.         {
    168.             message1[7] = T_Byte1/10 + 48;      // Extract the tens place
    169.             message1[8] = T_Byte1 + 48;      // Extract the ones place
    170.             message1[10]= T_Byte2/10 + 48;      // Extract the decimal
    171.             message1[11] = 223;                 // ASCII code for degree symbol  
    172.             message2[7] = RH_Byte1/10 + 48;     // Extract the tens place
    173.             message2[8] = RH_Byte1 + 48;     // Extract the ones place
    174.             message2[10] = RH_Byte2/10 + 48;    // Extract the decimal
    175.  
    176.             WriteCmdXLCD(0x01);
    177.             putrsXLCD(message1);    // Write the temp to LCD
    178.             SetDDRamAddr(0x40);
    179.             putrsXLCD(message2);    // Write the humidity to LCD
    180.         }
    181.         else {                      // Checksum is not correct
    182.             WriteCmdXLCD(0x01);
    183.             putrsXLCD("Checksum error!");
    184.             SetDDRamAddr(0x40);
    185.             putrsXLCD("Please wait.");
    186.         }
    187.         }
    188.     } while (1);    // Do it forever.
    189. }
    190.  
     
    Last edited: Feb 29, 2016
    atferrari likes this.
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    Are you going to tell us the error? Or do you want to keep that a secret?
     
  10. new999

    Thread Starter New Member

    Jan 18, 2016
    12
    0
    If you read my question it is clearly written that i am getting a configuration code error.
     
  11. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    The code is written for Microchips XC8 compiler. It will not compile in MikroC.

    You have to write the code for MikroC.

    Do you have a link to your Genius Software?
     
Loading...