betuse
Junior Member level 3
- Joined
- Oct 17, 2013
- Messages
- 26
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 173
Hi for all,
I use EasyMx Pro for Stellaris board with LM4F232 (Cortex M4) mcu,
I need to read temp from 18B20, but on TFT I only have 000.0625 C,
sensor in connected on PD4 port
the code is
can somebody advice?
regards
I use EasyMx Pro for Stellaris board with LM4F232 (Cortex M4) mcu,
I need to read temp from 18B20, but on TFT I only have 000.0625 C,
sensor in connected on PD4 port
the code is
Code:
// TFT module connections
char TFT_DataPort at GPIO_PORTJ_DATA;
sbit TFT_RST at GPIO_PORTH_DATA5_bit;
sbit TFT_RS at GPIO_PORTG_DATA7_bit;
sbit TFT_CS at GPIO_PORTH_DATA6_bit;
sbit TFT_RD at GPIO_PORTC_DATA5_bit;
sbit TFT_WR at GPIO_PORTH_DATA4_bit;
sbit TFT_BLED at GPIO_PORTA_DATA3_bit;
char TFT_DataPort_Direction at GPIO_PORTJ_DIR;
sbit TFT_RST_Direction at GPIO_PORTH_DIR5_bit;
sbit TFT_RS_Direction at GPIO_PORTG_DIR7_bit;
sbit TFT_CS_Direction at GPIO_PORTH_DIR6_bit;
sbit TFT_RD_Direction at GPIO_PORTC_DIR5_bit;
sbit TFT_WR_Direction at GPIO_PORTH_DIR4_bit;
sbit TFT_BLED_Direction at GPIO_PORTA_DIR3_bit;
// End TFT module connections
// Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
// 18S20: 9 (default setting; can be 9,10,11,or 12)
// 18B20: 12
const unsigned short TEMP_RESOLUTION = 12;
char *text = "000.0000 C";
unsigned temp;
void DrawScr() {
TFT_Init_ILI9341_8bit(320, 240);
TFT_Fill_Screen(CL_WHITE);
TFT_Set_Pen(CL_Black, 2);
TFT_Line(20, 220, 300, 220);
TFT_LIne(20, 46, 300, 46);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("Temperature sensor (18B20)", 20, 14);
TFT_Set_Font(&Verdana12x13_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("Cortex M4", 19, 223);
TFT_Set_Font(&Verdana12x13_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("LM4F232", 256, 223);
TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
}
void Display_Temperature(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
char temp_whole;
unsigned int temp_fraction;
// Check if temperature is negative
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
}
// Extract temp_whole
temp_whole = temp2write >> RES_SHIFT ;
// Convert temp_whole to characters
if (temp_whole/100)
text[0] = temp_whole/100 + 48;
else
text[0] = '0';
text[1] = (temp_whole/10)%10 + 48; // Extract tens digit
text[2] = temp_whole%10 + 48; // Extract ones digit
// Extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
// Convert temp_fraction to characters
text[4] = temp_fraction/1000 + 48; // Extract thousands digit
text[5] = (temp_fraction/100)%10 + 48; // Extract hundreds digit
text[6] = (temp_fraction/10)%10 + 48; // Extract tens digit
text[7] = temp_fraction%10 + 48; // Extract ones digit
text[9] = 176;
// Print temperature on TFT
TFT_Set_Font(&tahoma29x29_Bold, CL_RED, FO_HORIZONTAL);
TFT_Write_Text(text, 85, 100);
}
void main() {
TFT_Set_Default_Mode();
DrawScr();
TFT_Set_Font(&tahoma29x29_Bold, CL_BLACK, FO_HORIZONTAL);
TFT_Write_Text("Temperature: ", 75, 65);
GPIO_Digital_Input(&GPIO_PORTD, _GPIO_PINMASK_ALL); // all pins on PD is digital input
// Main loop
do {
// Perform temperature reading
Ow_Reset(&GPIO_PORTD_AHB_DATA, 4); // Onewire reset signal
Ow_Write(&GPIO_PORTD_AHB_DATA, 4, 0xCC); // Issue command SKIP_ROM
Ow_Write(&GPIO_PORTD_AHB_DATA, 4, 0x44); // Issue command CONVERT_T
Delay_ms(750);
Ow_Reset(&GPIO_PORTD_AHB_DATA, 4);
Ow_Write(&GPIO_PORTD_AHB_DATA, 4, 0xCC); // Issue command SKIP_ROM
Ow_Write(&GPIO_PORTD_AHB_DATA, 4, 0xBE); // Issue command READ_SCRATCHPAD
temp = Ow_Read(&GPIO_PORTD_AHB_DATA, 4);
temp = (Ow_Read(&GPIO_PORTD_AHB_DATA, 4) << 8) + temp;
// Format and display result on TFT
Display_Temperature(temp);
Delay_ms(1000);
} while (1);
}
can somebody advice?
regards