Revision 291 trunk/programmer/test/main.c
| main.c (revision 291) | ||
|---|---|---|
| 1 |
/******** |
|
| 2 |
* This file is part of Tooltron. |
|
| 1 |
/******** * This file is part of Tooltron. |
|
| 3 | 2 |
* |
| 4 | 3 |
* Tooltron is free software: you can redistribute it and/or modify |
| 5 | 4 |
* it under the terms of the Lesser GNU General Public License as published by |
| ... | ... | |
| 29 | 28 |
#include <util/delay.h> |
| 30 | 29 |
#include <avr/wdt.h> |
| 31 | 30 |
#include <avr/eeprom.h> |
| 31 |
#include "../../common/toolbox_pindefs.h" |
|
| 32 |
#include "../../common/tooltron.h" |
|
| 33 |
#include "../../toolbox/jumptable.h" |
|
| 32 | 34 |
|
| 33 |
#define RELAY _BV(PORTD4) |
|
| 34 |
#define VAC_SENSE _BV(PIND3) |
|
| 35 |
#define BUT_RED _BV(PINB4)#define BUT_BLACK _BV(PINB3) |
|
| 36 |
#define LED_GREEN _BV(PORTB2) |
|
| 37 |
#define LED_YELLOW _BV(PORTB1) |
|
| 38 |
#define LED_RED _BV(PORTB0) |
|
| 39 |
#define ON 0x01 |
|
| 40 |
#define OFF 0x00 |
|
| 35 |
/* #define RELAY _BV(PORTD4) */ |
|
| 36 |
/* #define VAC_SENSE _BV(PIND3) */ |
|
| 37 |
/* #define BUT_RED _BV(PINB4)#define BUT_BLACK _BV(PINB3) */ |
|
| 38 |
/* #define LED_GREEN _BV(PORTB2) */ |
|
| 39 |
/* #define LED_YELLOW _BV(PORTB1) */ |
|
| 40 |
/* #define LED_RED _BV(PORTB0) */ |
|
| 41 |
/* #define ON 0x01 */ |
|
| 42 |
/* #define OFF 0x00 */ |
|
| 41 | 43 |
|
| 42 | 44 |
/***** change ADDR ****/ |
| 43 | 45 |
#define ADDR 14 |
| ... | ... | |
| 95 | 97 |
} |
| 96 | 98 |
|
| 97 | 99 |
int main(int argc, char **argv) {
|
| 98 |
state_t state = sd; |
|
| 99 |
uint8_t packet[3]; |
|
| 100 |
uint8_t ms_timer=0; |
|
| 101 | 100 |
|
| 102 |
uint8_t myaddr; |
|
| 101 |
uint8_t mbuf[PROGD_PACKET_SIZE]; // ignored |
|
| 102 |
uint8_t len; |
|
| 103 |
|
|
| 103 | 104 |
/***** Start Start-up Sequence *****/ |
| 104 |
init_pins(); //Set pin directions |
|
| 105 |
init_pins(); //Set pin directions |
|
| 105 | 106 |
// init_uart(51); //Set registers for uart |
| 106 | 107 |
/***** End Start-up Sequence *****/ |
| 107 | 108 |
|
| 108 |
uint8_t r; |
|
| 109 |
uint8_t a,b,c, correct; |
|
| 109 | 110 |
|
| 110 |
//eeprom_write_byte(1, ADDR); |
|
| 111 |
eeprom_write_byte(EEPROM_ADDR1, ADDR); |
|
| 112 |
eeprom_write_byte(EEPROM_ADDR2, ADDR); |
|
| 113 |
eeprom_write_byte(EEPROM_ADDR3, ADDR); |
|
| 111 | 114 |
|
| 112 | 115 |
PORTB = 0x7; |
| 113 | 116 |
|
| 114 |
myaddr = eeprom_read_byte(1); |
|
| 115 |
if (myaddr == ADDR) {
|
|
| 116 |
PORTB = 0; |
|
| 117 |
while(1) {
|
|
| 118 |
_delay_ms(1000); |
|
| 119 |
PORTB |= _BV(PORTB2); |
|
| 120 |
_delay_ms(1000); |
|
| 121 |
PORTB &= ~_BV(PORTB2); |
|
| 122 |
} |
|
| 117 |
a = eeprom_read_byte(EEPROM_ADDR1); |
|
| 118 |
b = eeprom_read_byte(EEPROM_ADDR2); |
|
| 119 |
c = eeprom_read_byte(EEPROM_ADDR3); |
|
| 120 |
|
|
| 121 |
correct = (a == ADDR) + (b == ADDR) + (c == ADDR); |
|
| 122 |
|
|
| 123 |
if ( correct == 3 ) {
|
|
| 124 |
PORTB |= LED_GREEN; |
|
| 123 | 125 |
} |
| 124 |
_delay_ms(1000); |
|
| 125 |
PORTB |= _BV(PORTB0); |
|
| 126 |
_delay_ms(1000); |
|
| 127 |
reset(); |
|
| 126 |
else if(correct == 0){
|
|
| 127 |
PORTB |= LED_RED; |
|
| 128 |
} |
|
| 129 |
else {
|
|
| 130 |
PORTB |= LED_YELLOW; |
|
| 131 |
} |
|
| 128 | 132 |
|
| 133 |
|
|
| 129 | 134 |
while(1) {
|
| 130 |
_delay_ms(1000); |
|
| 131 |
PORTB |= _BV(PORTB0); |
|
| 132 |
_delay_ms(1000); |
|
| 133 |
PORTB &= ~_BV(PORTB0); |
|
| 135 |
parse_packet(mbuf, &len, ADDR); |
|
| 134 | 136 |
} |
| 135 | 137 |
|
| 136 | 138 |
return 0; |
Also available in: Unified diff