p77
Newbie level 3
Hello everyone,
This is my first post to the forum, but I have been reading/using it for quite a while and I must thank you all for contributing and helping. Sorry for my english, its a foreign language to me.
Equipment:
Two temperature sensors 18B20 each interfaced via separate OneWire comm.
12864B GLCD
DS3231 RTC via software I2C
PIC 16F887
Issue:
The following code bellow programmed and the alterations i make and issues are following:
When all of the function calls in while loop in function main are uncommented the microcontroller doesnt even jump into program, eg. not working.
If I comment read/display date functions, everything what is left work perfectly fine, the menu, two temperature readouts and current time.
If I comment two temperature readouts and leave time and date readout uncommented, again what is left in the program do work.
This led me to following belief that I have done something horribly stupid and wrong with declarations and am experiencing some memory issue, so I switched to 18F4550 with 5 times the RAM and Program memory of 887. Again, the issue is the same.
So let me put this together one more time: All of my functions work fine but without luck to use them all .
Secondary code:
Header file:
And that would be it. I have lost 70 hours debugging this and I am really tired so i think it is ok to finally ask for help.
Thank you all,
p77.
This is my first post to the forum, but I have been reading/using it for quite a while and I must thank you all for contributing and helping. Sorry for my english, its a foreign language to me.
Equipment:
Two temperature sensors 18B20 each interfaced via separate OneWire comm.
12864B GLCD
DS3231 RTC via software I2C
PIC 16F887
Issue:
The following code bellow programmed and the alterations i make and issues are following:
When all of the function calls in while loop in function main are uncommented the microcontroller doesnt even jump into program, eg. not working.
If I comment read/display date functions, everything what is left work perfectly fine, the menu, two temperature readouts and current time.
If I comment two temperature readouts and leave time and date readout uncommented, again what is left in the program do work.
This led me to following belief that I have done something horribly stupid and wrong with declarations and am experiencing some memory issue, so I switched to 18F4550 with 5 times the RAM and Program memory of 887. Again, the issue is the same.
So let me put this together one more time: All of my functions work fine but without luck to use them all
Code:
#include "UART.h"
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit Soft_I2C_Scl at RA3_bit;
sbit Soft_I2C_Sda at RA4_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
sbit Soft_I2C_Scl_Direction at TRISA3_bit;
sbit Soft_I2C_Sda_Direction at TRISA4_bit;
void Convert_Time(unsigned short tc) {
int ac=0, ic=0;
int bits[8]={0,0,0,0,0,0,0,0};
for (ic=128, ac=7; ic>=1; ic=ic/2)
{
bits[ac]=tc/ic;
if (bits[ac]) {tc=tc%ic;}
ac--;
}
tc=(((bits[6]*4)+(bits[5]*2)+(bits[4]*1))*10)+(bits[3]*8)+(bits[2]*4)+(bits[1]*2)+(bits[0]*1);
echo1[0]=(tc/10)+48;
echo1[1]=(tc%10)+48;
return;
}
void Convert_Month(unsigned short tc) {
int ac=0, ic=0;
int bits[8]={0,0,0,0,0,0,0,0};
for (ic=128, ac=7; ic>=1; ic=ic/2)
{
bits[ac]=tc/ic;
if (bits[ac]) {tc=tc%ic;}
ac--;
}
tc=(((bits[5]*2)+(bits[4]*1))*10)+(bits[3]*8)+(bits[2]*4)+(bits[1]*2)+(bits[0]*1);
echo2[0]=(tc/10)+48;
echo2[1]=(tc%10)+48;
return;
}
void Read_Time(){
Soft_I2C_Init();
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0b11010000); // Start from address 2
Soft_I2C_Write(0x00);
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0b11010001);
rtc_seconds = Soft_I2C_Read(1);
rtc_minutes = Soft_I2C_Read(1);
rtc_hours = Soft_I2C_Read(0);
Soft_I2C_Stop();
return;
}
void Read_Date(){
Soft_I2C_Init();
Soft_I2C_Start();
Soft_I2C_Write(0b11010000);
Soft_I2C_Write(0x03);
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0b11010001);
rtc_day = Soft_I2C_Read(1);
rtc_date = Soft_I2C_Read(1);
rtc_month = Soft_I2C_Read(1);
rtc_year = Soft_I2C_Read(0);
Soft_I2C_Stop();
return;
}
void PrintMenu(){
Glcd_Write_Text(Brand, 59, 0, 2);
Glcd_Write_Text(PrintT, 0, 7, 2);
Glcd_Write_Text(MenuT, 37, 7, 2);
Glcd_Write_Text(BackT, 74, 7, 2);
Glcd_Write_Text(SetT, 108, 7, 2);
return;
}
void RTC_Init(){
Soft_I2C_Start();
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0xF);
Soft_I2C_Write(0x00);
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0xE);
Soft_I2C_Write(0x00);
Soft_I2C_Stop();
return;
}
void Display_Time(){
Convert_Time(rtc_hours);
rtc_time_string[0]=echo1[0];
rtc_time_string[1]=echo1[1];
Convert_Time(rtc_minutes);
rtc_time_string[3]=echo1[0];
rtc_time_string[4]=echo1[1];
Convert_Time(rtc_seconds);
rtc_time_string[6]=echo1[0];
rtc_time_string[7]=echo1[1];
Glcd_Write_Text(rtc_time_string, 0, 4, 2);
return;
}
void Display_Date(){
Convert_Time(rtc_date);
rtc_date_string[0]=echo1[0];
rtc_date_string[1]=echo1[1];
Convert_Month(rtc_month);
rtc_date_string[3]=echo2[0];
rtc_date_string[4]=echo2[1];
Convert_Time(rtc_year);
rtc_date_string[8]=echo1[0];
rtc_date_string[9]=echo1[1];
Glcd_Write_Text(rtc_date_string, 0, 3, 2);
return;
}
void main() {
INTCON = 0;
INTCON2 = 0xF5;
INTCON3 = 0xC0;
RCON.IPEN = 0;
PIE1 = 0;
PIE2 = 0;
PIR1 = 0;
PIR2 = 0;
ADCON1 |= 0x0F;
CMCON |= 7;
Soft_I2C_Init();
UART1_Init(19200);
Delay_ms(200);
RTC_Init();
Glcd_Init();
Glcd_Fill(0x00);
Glcd_Set_Font(System3x5, 3, 5, 32);
while (1) {
//Read_Time();
Read_Date();
Read_Temp2();
//Read_Temp1();
Glcd_Fill(0x00);
//Display_Time();
Display_Date();
PrintMenu();
Display_Temperature2();
//Display_Temperature1();
Delay_ms(300);
}
}
Secondary code:
Code:
#define t1t "TEMP 1:"
#define t2t "TEMP 2:"
extern unsigned temp1, temp2;
const unsigned short TEMP_RESOLUTION = 12;
extern char text1[];
extern char text2[];
extern char Temp1T[];
extern char Temp2T[];
extern char temp_whole;
const unsigned short RES_SHIFT2=4;
void Display_Temperature1() {
unsigned int temp_fraction;
char temp_whole2;
unsigned int temp_fraction2;
if (temp1 & 0x8000)
{
text1[0] = '-';
temp1 = ~temp1 + 1;
}
temp_whole2 = temp1 >> RES_SHIFT2 ;
if (temp_whole2/100)
text1[0] = temp_whole2/100 + 48;
else
text1[0] = ' ';
text1[1] = (temp_whole2/10)%10 + 48;
text1[2] = temp_whole2%10 + 48;
temp_fraction2 = temp1 << (4-RES_SHIFT2);
temp_fraction2 &= 0x000F;
temp_fraction2 *= 625;
text1[4] = temp_fraction2/1000 + 48;
text1[5] = (temp_fraction2/100)%10 + 48;
text1[6] =' ';
text1[7] = 'C';
Glcd_Write_Text(t1t, 0, 5, 2);
Glcd_Write_Text(text1, 60, 5, 2);
return;
}
void Display_Temperature2() {
unsigned int temp_fraction;
char temp_whole2;
unsigned int temp_fraction2;
if (temp2 & 0x8000)
{
text2[0] = '-';
temp2 = ~temp2 + 1;
}
temp_whole2 = temp2 >> RES_SHIFT2 ;
if (temp_whole2/100)
text2[0] = temp_whole2/100 + 48;
else
text2[0] = ' ';
text2[1] = (temp_whole2/10)%10 + 48;
text2[2] = temp_whole2%10 + 48;
temp_fraction2 = temp2 << (4-RES_SHIFT2);
temp_fraction2 &= 0x000F;
temp_fraction2 *= 625;
text2[4] = temp_fraction2/1000 + 48; // Extract thousands digit
text2[5] = (temp_fraction2/100)%10 + 48; // Extract hundreds digit
text2[6] =' ';//(temp_fraction/10)%10 + 48; // Extract tens digit
text2[7] = 'C'; //temp_fraction%10 + 48; // Extract ones digit
Glcd_Write_Text(t2t, 0, 6, 2);
Glcd_Write_Text(text2, 60, 6, 2);
return;
}
void Read_Temp1(){
Ow_Reset(&PORTE, 2);
Ow_Write(&PORTE, 2, 0xCC);
Ow_Write(&PORTE, 2, 0x44);
Ow_Reset(&PORTE, 2);
Ow_Write(&PORTE, 2, 0xCC);
Ow_Write(&PORTE, 2, 0xBE);
temp1 = Ow_Read(&PORTE, 2);
temp1 = (Ow_Read(&PORTE, 2) << 8) + temp1;
return;
}
void Read_Temp2(){
Ow_Reset(&PORTE, 1);
Ow_Write(&PORTE, 1, 0xCC);
Ow_Write(&PORTE, 1, 0x44);
Ow_Reset(&PORTE, 1);
Ow_Write(&PORTE, 1, 0xCC);
Ow_Write(&PORTE, 1, 0xBE);
temp2 = Ow_Read(&PORTE, 1);
temp2 = (Ow_Read(&PORTE, 1) << 8) + temp2;
return;
}
Header file:
Code:
#define Brand "COLD MASTER 2016"
#define PrintT "PRINT"
#define MenuT "MENU"
#define BackT "BACK"
#define SetT "SET"
unsigned temp1, temp2;
unsigned short echo1[]= "00";
unsigned short echo2[]= "00";
unsigned int temp_fraction;
char rtc_time_string[]="00:00:00";
char rtc_date_string[]="xx/xx/20xx";
char text1[]= "000.0000";
char text2[]= "000.0000";
char rtc_seconds;
char rtc_minutes;
char rtc_hours;
char rtc_day;
char rtc_date;
char rtc_month;
char rtc_year;
char temp_whole;
void Convert_Time(unsigned short tc);
void Convert_Month(unsigned short tc);
void Read_Time();
void Display_Time();
void Read_Date();
void Display_Date();
void Print_Menu();
void RTC_Init();
void Read_Temp1();
void Display_Temperature1();
void Read_Temp2();
void Display_Temperature2();
And that would be it. I have lost 70 hours debugging this and I am really tired so i think it is ok to finally ask for help.
Thank you all,
p77.