I'm converting the C example for the sparkfun reflow oven from C for PIC16F88 to Arduino for ATMega328P.
Here's the soure:
http://www.crossroadsfencing.com/ToasterControl-v021.C
from here
Got most of it figured out I think, getting these errors to finish up:
oven_controller.cpp:722:13: error: macro "putc" requires 2 arguments, but only 1 given << lot of occurrences of this
oven_controller:49: error: expected initializer before 'serverX' << and this one twice
oven_controller:81: error: expected initializer before 'serverX'
Not sure how to fix it.
Probably need something in the EEPROM section aslo, not sure what.
Little help please?
My conversion, in thirds:
/*
4-26-05
Copyright Spark Fun Electronics© 2005
Nathan Seidle
spark@sparkfun.com
Basic control and monitoring of a Toaster oven for SMD reflowing.
The unit responds to these commands:
0x31 ('1') - Relay On : Activates the heating elements
0x32 ('2') - Relay Off : Deactivates the heating elements
0x63 ('c') - Temperature Check : Unit takes a temperature reading and responds with the 10-bit reading in two bytes
0x74 ('t') - Time Check : Unit reports total seconds run (ex: 138)
0x72 ('r') - Reset Time : Resets the total seconds.
Safety settings : The reflow toaster controller will shut off the relay if it does not
receive the Relay On command after 30 seconds.
This is a really nice example program that includes examples on how to do the following:
Standard HD44780 parallel interface to LCD
Print decimal numbers and strings to serial output as well as an LCD
Reading buttons
Real time clock (RTC) interrupts using an internal osc (not very accurate, but it works)
Doing an ADC on a thermocouple to get temperature
EEPROM Read and Write functions are also available for storing profiles
Oh, and of course we blink the Status LED
I've pulled all the functions into this one file for all of you who want to wade through the code.
We use a simple, cheap, thermocouple with the expensive AD595AQ Amplifier
*/
//#define Clock_8MHz
//#define Baud_9600
/* Rewritten for ATMega328 */
#define STATUS_LED 13
#define BUTTON_UP 11
#define BUTTON_DOWN 10
#define BUTTON_SELECT 9
#define RELAY 12
// #define OFF 0 Replaced with Low
// #define ON 1 Replaced with High
#define D7 7
#define D6 6
#define D5 5
#define D4 4
#define E 15
#define R_W 16
#define RS 17
#define CLR_DISP 0b00000001 //Clear display
#define CUR_HOME 0b00000010 //Move cursor home and clear screen memory
#define DISP_ON 0b00001100 //Turn visible LCD on
#define SET_CURSOR 0b10000000 //SET_CURSOR + X : Sets cursor position to X
byte m_seconds = 0;
byte seconds = 0;
int total_seconds = 0;
//#include "\Global\Code\C\16F88.h" // Device hardware map
//#include "\Global\Code\C\int16CXX.H" // Device interrupt definitions
#pragma config |= 0x2902
#pragma origin 4 //Used for boot loading and interrupts
//Global Variables
//============================
//byte m_seconds;
//byte seconds;
//int total_seconds; //Used in VB for thresholds
//============================
//End Global Variables
//Interrupt Vectors
//============================
void interrupt serverX() // ???
{
int_save_registers
char sv_FSR = FSR; // save FSR if required
if(TMR1IF) //Timer1 Overflow Interrupt
{
//Setup Timer1 to fire every 100ms
//1 TMR1 click is 4us (with prescaler of 8). 100ms / .004ms = 25000 clicks
//65535 - 25000 = 40535 = 0x9E57
TMR1ON = 0;
TMR1H = 0x9E;
TMR1L = 0x57;
TMR1ON = 1;
m_seconds++;
if(m_seconds == 10)
{
m_seconds = 0;
seconds++;
total_seconds++;
}
TMR1IF = 0; //Clear INT Flag
}
FSR = sv_FSR; // restore FSR if saved
int_restore_registers
}
//============================
//Function definitions
//============================
//#include "d:\Pics\code\Delay.c" // Delays
//#include "d:\Pics\code\Stdio.c" // Print routines
int check_temp(void);
void delay_ms(int16 x);
void send_char(byte);
void send_cmd(byte);
//void send_string(const char* incoming_string);
void LCD_wait(void);
void init_lcd(void);
void printf_lcd(const char *nate, int my_byte);
void putc(byte);
void getc();
void scanc();
void bin2Hex(char x);
void printf(const char *nate, int my_byte);
//============================
//End Function Definitions
void setup () {
// some kind of LCD Library for these 7??
pinMode (D4, OUTPUT);
digitalWrite (D4, LOW);
pinMode (D5, OUTPUT);
digitalWrite (D5, LOW);
pinMode (D6, OUTPUT);
digitalWrite (D6, LOW);
pinMode (D7, OUTPUT);
digital Write (D7, LOW);
pinMode (RELAY, OUTPUT);
digitalWrite (RELAY, LOW); // = off
pinMode (STATUS_LED, OUTPUT);
digitalWrite (STATUS_LED, HIGH); // = off
pinMode (RS, OUTPUT);
digitalWrite (RS, LOW);
pinMode (R_W, OUTPUT);
digitalWrite (R_W, LOW);
pinMode (E, OUTPUT);
digitalWrite (E, LOW);
pinMode (BUTTON_UP, INPUT);
digitalWrite (BUTTON_UP, HIGH);
pinMode (BUTTON_DOWN, INPUT);
digitalWrite (BUTTON_DOWN, HIGH);
pinMode (BUTTON_SELECT, INPUT);
pinMode (BUTTON_SELECT, HIGH);
pinMode (A5, TEMP);
Serial.begin (19200);
Serial.flush;
//Setup Timer1 for delay between measurements
T1CON = 0b00110000; //Prescale of 1:8 - 1 timer click = 4us with 8MHz internal osc
//Setup interrupts
TMR1IE = 1;
PEIE = 1;
GIE = 1;
TMR1ON = 1;
init_lcd();
printf_lcd(" SparkFun.com", 0);
send_cmd(SET_CURSOR + 64);
printf_lcd("ReflowToaster v2", 0);
delay(750);
send_cmd(CLR_DISP);
}
void loop ()
{
byte choice;
int adc_reading;
unsigned long temperature;
while(1)
{
if(seconds > 30)
{
RELAY = LOW; // off
printf("Emergency shut down", 0);
send_cmd(CLR_DISP);
printf_lcd("Emergency shut down", 0);
while(1)
{
STATUS_LED ^= 1; // ???
delay (500);
}
}
//Scan for buttons as we wait
//====================================================
if(digitalRead(BUTTON_SELECT) == 0)
{
while(digitalRead(BUTTON_SELECT) == 0); //Wait for user to remove finger
send_cmd(CLR_DISP);
printf_lcd("Select", 0);
printf("#SELECT$", 0);
}
if(digitalRead(BUTTON_UP) == 0)
{
while(digitalRead(BUTTON_UP) == 0); //Wait for user to remove finger
send_cmd(CLR_DISP);
printf_lcd("Up", 0);
printf("#UP$", 0);
}
if(digitalRead(BUTTON_DOWN) == 0)
{
while(digitalRead(BUTTON_DOWN) == 0); //Wait for user to remove finger
send_cmd(CLR_DISP);
printf_lcd("Down", 0);
printf("#DOWN$", 0);
}
//====================================================