24,7 → 24,7 |
int8 heat; // Status variables |
int8 open; |
|
inline void toggle_dome(void) |
inline void toggle_dome(void) // Wire exercise |
{ |
if (open>0) |
{output_toggle(DOME);} |
32,7 → 32,7 |
{output_low(DOME);} |
} |
|
void delay(int16 cycles) |
void delay(int16 cycles) // Wire exercise with delay |
{ |
int16 i; |
|
39,10 → 39,18 |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
} |
|
void welcome(void) // Welcome message |
{ |
printf("\n\r* Mrakomer %s (C) 2007 KAKL *\n\r",VER); // Welcome message |
printf("* %s *\n\r",REV); |
printf("<#sequence> <ambient [1/100 C]> <sky [1/100 C]> "); |
printf("<heating [s]> <dome [s]>\n\r\n\r"); |
} |
|
#include "smb.c" |
|
#include "smb.c" // System Management Bus driver |
|
|
// Read sensor RAM |
// Returns temperature in °K |
int16 ReadTemp(int8 addr, int8 select) |
53,17 → 61,17 |
|
addr<<=1; |
|
SMB_STOP_bit(); //If slave send NACK stop comunication |
SMB_START_bit(); //Start condition |
SMB_STOP_bit(); //If slave send NACK stop comunication |
SMB_START_bit(); //Start condition |
SMB_TX_byte(addr); |
SMB_TX_byte(RAM_Access|select); |
SMB_START_bit(); //Repeated Start condition |
SMB_START_bit(); //Repeated Start condition |
SMB_TX_byte(addr); |
arr[2]=SMB_RX_byte(ACK); //Read low data,master must send ACK |
arr[1]=SMB_RX_byte(ACK); //Read high data,master must send ACK |
arr[2]=SMB_RX_byte(ACK); //Read low data,master must send ACK |
arr[1]=SMB_RX_byte(ACK); //Read high data,master must send ACK |
temp=MAKE16(arr[1],arr[2]); |
crc=SMB_RX_byte(NACK); //Read PEC byte, master must send NACK |
SMB_STOP_bit(); //Stop condition |
crc=SMB_RX_byte(NACK); //Read PEC byte, master must send NACK |
SMB_STOP_bit(); //Stop condition |
|
arr[5]=addr; |
arr[4]=RAM_Access|select; |
74,6 → 82,7 |
return temp; |
} |
|
/*-----------------------------------------------------------------------*/ |
void main() |
{ |
unsigned int16 seq, temp, tempa; |
80,6 → 89,7 |
signed int16 ta, to; |
int8 safety_counter; |
|
output_low(DOME); // Close Dome |
output_low(HEATING); // Heating off |
setup_wdt(WDT_2304MS); // Setup Watch Dog |
setup_adc_ports(NO_ANALOGS); |
94,30 → 104,25 |
|
delay_ms(1000); |
restart_wdt(); |
printf("\n\r* Mrakomer %s (C) 2007 KAKL *\n\r",VER); // Welcome message |
printf("* %s *\n\r",REV); |
printf("<#sequence> <ambient [1/100 C]> <sky [1/100 C]> "); |
printf("<heating [s]> <dome [s]>\n\r\n\r"); |
|
welcome(); |
|
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
temp=ReadTemp(SA, RAM_Tobj1); |
|
seq=0; |
seq=0; // Variables initiation |
heat=0; |
open=0; |
|
// enable_interrupts(GLOBAL); |
// enable_interrupts(INT_RDA); |
|
//---WDT |
restart_wdt(); |
|
while(TRUE) |
while(TRUE) // Main Loop |
{ |
while(kbhit()) getc(); // Flush USART buffer |
CREN=0; CREN=1; // Reinitialise USART |
|
safety_counter=0; |
|
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
do |
{ |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
143,10 → 148,10 |
restart_wdt(); |
} |
} while (!kbhit()); |
|
|
//---WDT |
restart_wdt(); |
{ |
{ // Retrieve command |
char ch; |
|
ch=getc(); |
165,9 → 170,18 |
open=MAXOPEN; // Open the dome |
break; |
|
case 'x': |
open=MAXOPEN; // Open the dome |
heat=MAXHEAT; // Need heating |
break; |
|
case 'l': |
open=0; // Lock the dome |
break; |
|
case 'i': |
welcome(); // Information about version, etc... |
break; |
} |
} |
|
180,8 → 194,8 |
to=temp*2-27315; |
|
{ // printf |
char output[10]; // Output buffer |
int8 j; // Counter |
char output[8]; // Output buffer |
int8 j; // String pointer |
|
delay(SEND_DELAY); |
sprintf(output,"#%Lu ", seq); |