I can't open your file. Why don't you use the code-tags in the editor's menu and show us your code?This is made in MPlab however there is some error. pl help me correct it and send the hex file.
/* 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.
}
Are you going to tell us the error? Or do you want to keep that a secret?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.
If you read my question it is clearly written that i am getting a configuration code error.Are you going to tell us the error? Or do you want to keep that a secret?
The code is written for Microchips XC8 compiler. It will not compile in MikroC.How do i go about it in mikroc for pic as i have used it to program the pic.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
F | Differences 3D Printer Boards Artillery MKS GenL V1.0 X1 and Genius | General Electronics Chat | 0 | |
![]() |
One more expert genius... | Off-Topic | 1 | |
![]() |
The genius of Apollo | Off-Topic | 61 | |
![]() |
Idiot with circuits, Genius with ideas. | Off-Topic | 23 | |
![]() |
Looking for a radiocontrol tinkerer genius... | Off-Topic | 18 |