To už jsem zkoušel předtím. Teď jsem to zkoušel znovu. To řádkování to sice napraví, ale když po tomto rozdělení dlouhého řetězce použiju funkci lcd_gotoxy (0,2), tak mi to další text vypíše na začátek 2. řádku a né třetího jak chci.
Do programu jsem doplnil nějaké pauzy a udělal jsem video s WRAP 0 a WRAP 1.
WRAP 0: youtube.com/watch?v=G3kJbcKZ2zw
WRAP 1: youtube.com/watch?v=7ll90bpI9rY
kod v main.c je teď tento:
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <string.h>
#include "owi_highlevel.h"
#include "ds18x20.h"
#include "lcd.h"
#include "delay.h"
#include "crc.h"
#define MAX_SENSORS 10 // we can handle only sensor ID's from 0-9 (display constraint on order page)
uint8_t gSensorIDs[MAX_SENSORS][OWI_ROMCODE_SIZE]; // active 1-wire thermometer sensors
uint8_t g1Wire_order[MAX_SENSORS]; // contains output ordering of 1-Wire thermometer devices
int gReadings[MAX_SENSORS]; // contains decicelsius readings for all thermometer sensors
char gBuffer[21]; // used for itoa conversions and sprintf buffer
int gLog_interval; // time period between log entries
// forward declarations
uint8_t onewire_search( void);
void display_temperatures( uint8_t num_sensors);
void read_temperatures( uint8_t num_sensors);
/****************************************************************************************
* *
* Main Entry Point *
* *
****************************************************************************************/
int main( void)
{
uint8_t num_sensors, tmp, i;
lcd_init( LCD_DISP_ON_BLINK);
lcd_clrscr();
lcd_led(1);
//lcd_command(1<<LCD_FUNCTION_4BIT_1LINE);
lcd_puts_P( "Nazdar");
delay_ms(2000); // pause lcd display for a moment
lcd_clrscr();
lcd_puts("Hledam cidla a vsechny veci kolem");
delay_ms(2000);
// get attached 1-wire sensor info
num_sensors = onewire_search();
if( num_sensors == 0)
{
lcd_clrscr();
lcd_puts_P( "Neni pripojen senzor");
while( 1); // nothing to do - stop further processing
}
// display the count of sensors found on 1-Wire bus
itoa( (int)num_sensors, gBuffer, 10);
lcd_gotoxy( 0, 3);
lcd_puts( gBuffer);
lcd_puts( " Senzor(y)");
delay_ms( 2000); // pause lcd display for a moment
lcd_clrscr();
for (tmp = 0; tmp < num_sensors; tmp++)
{
for (i = (OWI_ROMCODE_SIZE - 1); i < 255 ; i--)
{
itoa( (int)gSensorIDs[tmp]*, gBuffer, 16);
lcd_puts(gBuffer);
lcd_puts(" ");
}
delay_ms(3000);
lcd_gotoxy(0,2);
delay_ms(3000);
//lcd_gotoxy(0,3);
delay_ms(3000);
}
for (;;)
{
read_temperatures(num_sensors);
lcd_gotoxy(10,1);
display_temperatures(0);
lcd_gotoxy(10,3);
display_temperatures(1);
}
}
/****************************************************************************************
* *
* Helper Functions *
* *
****************************************************************************************/
// search 1-wire bus for active devices
uint8_t onewire_search( void)
{
uint8_t i, diff, num_sensors;
uint8_t id[OWI_ROMCODE_SIZE];
num_sensors = 0;
for( diff = OWI_SEARCH_FIRST;
diff != OWI_LAST_DEVICE && num_sensors < MAX_SENSORS ;)
{
diff = owi_search( diff, &id[0], OWI_SEARCH_ROM); // search all sensors
if( diff == OWI_PRESENCE_ERROR)
{
lcd_clrscr();
lcd_puts_P( "neni senzor");
break;
}
else if( diff == OWI_DATA_ERR)
{
lcd_clrscr();
lcd_puts_P( "Bus Error");
break;
}
else if( ! crc8( id, OWI_ROMCODE_SIZE)) // is it a valid id?
{
if( OWI_FAMILY( id[0]) == DS18B20_FAMILY_CODE || OWI_FAMILY( id[0]) == DS18S20_FAMILY_CODE)
{
for( i = 0; i < OWI_ROMCODE_SIZE; i++)
gSensorIDs[num_sensors]* = id*;
num_sensors++;
}
}
else
{
// id failed CRC check
lcd_puts_P( "CRC failed ");
}
}
return num_sensors;
}
// display one page of most recent temperature data on lcd
void display_temperatures( uint8_t num_sensors)
{
//uint8_t device;
// should always have at least one sensor on a page
//lcd_home();
//device = g1Wire_order[page];
sprintf( gBuffer, "%01i.%c C", gReadings[num_sensors] / 10, (gReadings[num_sensors] % 10) + '0');
lcd_puts( gBuffer);
/*
// is there a second sensor to display?
if( (page + 1) < num_sensors)
{
device = g1Wire_order[page + 1];
sprintf( gBuffer, "%02i%+04i.%c",
(int)page + 1, gReadings[device] / 10,
(gReadings[device] % 10) + '0');
lcd_puts( gBuffer);
}
else lcd_puts_P( " ");
*/
}
// read all DS18x20 sensors on 1-wire buss
void read_temperatures( uint8_t num_sensors)
{
uint8_t i;
if( DS18X20_start_meas( NULL) == OWI_BUS_OK)
{
for( i = 0; i < num_sensors; i++)
gReadings* = DS18X20_get_temp( &gSensorIDs*[0]);
}
else
{
for( i = 0; i < num_sensors; i++)
gReadings* = 0;
lcd_puts_P( "Start meas. fail");
}
}
Když jsem se znovu pořadně zamyslel a koukl do datashetu, tak mi došlo proč je to stím WRAP 0 tak rozházené. Je to podle adres DDRAM jak jdou po sobě 1. řádek - 3. řádek - 2. řádek - 4. řádek.
Ale pořád nevím proč to “blbne” s tím WRAP 1.******