Robtillaart, AWOL,
Thanks for your interest.
The code is a big listing. Please do not criticize, because it is my first C program. I normally write in assembly code. Here is the code:
#include <DogLcd.h>
#include "EEPROM.h"
/*
* PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
*
* Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* To use this sketch, connect the eight pins from your LCD like thus:
*
* Pin 1 VCC -> +3.3V (rightmost, when facing the display head-on)
* Pin 2 GND -> Ground
* Pin 3 SCE -> Arduino digital pin 7
* Pin 4 RST -> Arduino digital pin 6
* Pin 5 D/C -> Arduino digital pin 5
* Pin 6 MOSI -> Arduino digital pin 4
* Pin 7 SCLK -> Arduino digital pin 3
* Pin 8 LED -> 10uF capacitor -> Ground LED
*
* Since these LCDs are +3.3V devices, you have to add extra components to
* connect it to the digital pins of the Arduino (not necessary if you are
* using a 3.3V variant of the Arduino, such as Sparkfun's Arduino Pro).
*/
#include <PCD8544.h>
// A custom glyph (a smiley)...
static const byte glyph[] = { B00010100, B00100000, B00100000, B00100000, B00010100 };
static const byte airplane_widht = 84;
static const byte airplane_height = 42;
static const byte airplane[] = {
0x00, 0x00, 0xC0, 0x60, 0x20, 0x60, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x38, 0x28, 0xE4, 0xC4, 0x0C, 0x08, 0x18,
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1C, 0xFC, 0x84, 0x04, 0x78, 0xE0, 0x01, 0x02, 0x04,
0x04, 0x08, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x38, 0x0C, 0x46, 0x01, 0xC0, 0x74, 0x1C, 0x07,
0x01, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xBE, 0xE0,
0xC9, 0xC7, 0xFC, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x04, 0x04, 0x0C, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x04,
0x04, 0x04, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x81, 0x81, 0x81, 0x01, 0x03, 0x02, 0x02, 0x02, 0x02, 0xE2,
0x22, 0xB4, 0xF4, 0x98, 0xF0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xCC,
0x82, 0x81, 0xC1, 0xC0, 0x40, 0x60, 0x20, 0x70, 0xB8, 0xA8, 0xE5, 0xC3, 0xC0, 0x40, 0xC0, 0xC0,
0xC0, 0x80, 0x80, 0x80, 0x80, 0x87, 0x89, 0x89, 0x89, 0x87, 0x80, 0x80, 0x80, 0x80, 0x8F, 0xC9,
0xC9, 0xCB, 0xC7, 0x40, 0x40, 0x40, 0x40, 0x47, 0x49, 0xC9, 0x8D, 0x87, 0x80, 0x80, 0x80, 0x80,
0x87, 0x8D, 0x89, 0x8D, 0x87, 0x80, 0x80, 0x80, 0x80, 0x83, 0x87, 0x84, 0x85, 0x83, 0x80, 0x80,
0x80, 0x80, 0x80, 0x81, 0xC1, 0xC1, 0x41, 0xE0, 0xA0, 0xB0, 0x9E, 0x7F, 0x3F, 0x1E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC1,
0x41, 0x41, 0x61, 0x23, 0x33, 0x1B, 0x9B, 0x8B, 0xCF, 0x46, 0x43, 0x43, 0x61, 0x21, 0x11, 0x18,
0x08, 0x0C, 0x04, 0x06, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0x11, 0x19, 0x0F, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
0x04, 0x04, 0x04, 0x04, 0x06, 0x06, 0x06, 0x02, 0x02, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x1B,
0x31, 0x21, 0x23, 0x23, 0x22, 0x22, 0x26, 0x22, 0x23, 0x21, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20,
0x30, 0x10, 0x10, 0x10, 0x10, 0x18, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0E, 0x1A, 0x1A,
0x1F, 0x1F, 0x31, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static PCD8544 lcd;
char data=0;
int data_count=2;
uint8_t received_byte;
static uint8_t GPS_data[46]={0xB5,0x62,0x01,0x05};
uint8_t frame_count;
uint8_t sync_frame=0;
uint8_t frame_data;
unsigned long barometric_pressure=0;
unsigned long temp_pressure;
unsigned long pressure;
float altitude_barometric=0;
const double pressure_zero=101235;
const float v_divider_ratio=0.1960; // = 22K/(22K+91K)
int ad_voltage=0;
float bat_voltage=0;
float temp=0;
const float I_samples=4.00;
long int latitude;
long int longitude;
long int al_titude;
long int g_speed;
long int z;
float actual_longitude;
float actual_latitude;
long int z_int;
long int r;
char lat='N';
char lgt='W';
uint16_t RPM_value=0;
uint16_t current_ad=0;
uint16_t delta_I=0;
uint16_t temperature_ad=0;
float temperature=0;
float I_ad=0;
const float adc_bit=0.0049076;
float mAH=0;
float a_volt=0.099; // milivolts/ampere
float I_instantaneo=0;
float avg_sample=0;
float volt_element=3.5; // low limit alarm voltage cab be adjusted
float volt_element_adj=0;
int val=0;
uint8_t screen=0;
volatile uint16_t count=0;
volatile uint16_t time=0;
#define buzzerpin 9
#define LED 8
uint8_t bat_test=1;
uint8_t pressure_reset=1;
uint8_t j=0;
uint8_t element_count=0;
int read_pot_pin = A0; // select the input pin for the potentiometer
int pot_value = 0; // variable to store the value coming from the sensor
float I_max=0;
uint16_t rpm_max=0;
float bat_temp_max=0;
float altit_baro_max=0;
uint16_t veloc_max=0;
uint16_t altit_max=0;
float altit_baro_zero=0;
float altit_relativa=0;
const uint8_t switchpin=10;
uint8_t switch_state=0;
const float bit_value=0.004852;
float first_latitude=0;
float first_longitude=0;
uint8_t coordenadas=1;
float flat_distance=0;
float distance=0;
const float umgrau_lat=111.0;// Km
const float umgrau_long=83.91077; //Km
float delta_latitude=0;
float delta_longitude=0;
unsigned int address=0;
void setup()
{
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);
lcd.clear();
Serial.begin(9600);
// Add the smiley to position "0" of the ASCII table...
// lcd.createChar(0, glyph);
// Write a piece of text on the first line...
lcd.setCursor(4, 0);
lcd.print(" Hello, All! ");
// Write the counter on the second line...
lcd.setCursor(0, 1);
lcd.print(" I am alive ");
// lcd.write(' ');
// lcd.write(0); // write the smiley
delay(2000);
// counter++;
pinMode (buzzerpin, OUTPUT);
pinMode (LED, OUTPUT);
pinMode(13, OUTPUT);
pinMode(switchpin, INPUT);
pinMode(9, OUTPUT);
time=3500;
count=20;
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
//TCCR1A = (1<<COM1A0);
OCR1A = time; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode
// TCCR1B |= (1 << CS12)|(1<<CS10); // 1024 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
digitalWrite(buzzerpin, LOW); //switch OFF speaker
}