это код отправки
Код
unsigned int temp2write;
void main() {
CMCON=0x07; // Disable comparators
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) {
Ow_Reset(&PORTA, 0); // Onewire reset signal
Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0x44); // Issue command CONVERT_T
Delay_ms(120);
Ow_Reset(&PORTA, 0);
Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0xBE); // Issue command READ_SCRATCHPAD
temp2write = Ow_Read(&PORTA, 0);
temp2write = (Ow_Read(&PORTA, 0) << 8) + temp2write;
UART1_Write(temp2write);
Delay_ms(1500);
}
}
void main() {
CMCON=0x07; // Disable comparators
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) {
Ow_Reset(&PORTA, 0); // Onewire reset signal
Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0x44); // Issue command CONVERT_T
Delay_ms(120);
Ow_Reset(&PORTA, 0);
Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0xBE); // Issue command READ_SCRATCHPAD
temp2write = Ow_Read(&PORTA, 0);
temp2write = (Ow_Read(&PORTA, 0) << 8) + temp2write;
UART1_Write(temp2write);
Delay_ms(1500);
}
}
этим принимаю и вывожу на ЖК
Код
const unsigned short TEMP_RESOLUTION = 12;
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
char *text = " 000.00";
unsigned int temp_fraction,temp2write;
char temp_whole;
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void main() {
CMCON=0x07; // Disable comparators
UART1_Init(9600); // Initialize UART module a t9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Lcd_Init();
LCD_Cmd(_LCD_CLEAR); // Очистить дисплей
LCD_Cmd(_LCD_CURSOR_OFF); // Кусор выключен
while (1) {
if UART1_Data_Ready()
{
temp2write = UART1_Read();
}
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
}
temp_whole = temp2write >> RES_SHIFT;
text[1] = temp_whole/100 + 48;
text[2] = (temp_whole/10)%10 + 48; // Extract tens digit
text[3] = 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[5] = temp_fraction/1000 + 48;
text[6] = (temp_fraction/100)%10 + 48;
LCD_Out(1,1, text);
}
}
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
char *text = " 000.00";
unsigned int temp_fraction,temp2write;
char temp_whole;
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void main() {
CMCON=0x07; // Disable comparators
UART1_Init(9600); // Initialize UART module a t9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Lcd_Init();
LCD_Cmd(_LCD_CLEAR); // Очистить дисплей
LCD_Cmd(_LCD_CURSOR_OFF); // Кусор выключен
while (1) {
if UART1_Data_Ready()
{
temp2write = UART1_Read();
}
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
}
temp_whole = temp2write >> RES_SHIFT;
text[1] = temp_whole/100 + 48;
text[2] = (temp_whole/10)%10 + 48; // Extract tens digit
text[3] = 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[5] = temp_fraction/1000 + 48;
text[6] = (temp_fraction/100)%10 + 48;
LCD_Out(1,1, text);
}
}