Browse Source

Added spaces and cleaning up the structure.

master
Englebert 4 years ago
parent
commit
79549a7eb9
  1. 30
      programmer/programmer.ino

30
programmer/programmer.ino

@ -16,7 +16,7 @@
#define C2D_PORT PORTB // D10
#define C2D_PIN 2 // D10
// Digital pin 3 on Mega
// Digital pin D11 on arduino nano
#define C2CK_PORT PORTB // D11
#define C2CK_PIN 3 // D11
@ -58,6 +58,7 @@ static unsigned char c2_read_bits (unsigned char len) {
unsigned char i, data, mask;
mask = 0x01 << (len-1);
data = 0;
//pinMode(C2D, INPUT);
DDRB &= ~(1<<C2D_PIN);
PINB &= (1<<C2D_PIN);
@ -74,8 +75,10 @@ static unsigned char c2_read_bits (unsigned char len) {
return data;
}
static void c2_send_bits(unsigned char data, unsigned char len) {
unsigned char i;
//pinMode(C2D, OUTPUT);
DDRB |= (1<<C2D_PIN);
for(i=0; i<len; i++) {
@ -89,6 +92,7 @@ static void c2_send_bits (unsigned char data, unsigned char len) {
}
}
static void c2_write_data(unsigned char data) {
unsigned char retval;
c2_send_bits(0x0, 1);
@ -102,18 +106,21 @@ static void c2_write_data (unsigned char data) {
c2_send_bits(0x0, 1);
}
static unsigned char c2_poll_bit_high(unsigned char mask) {
unsigned char retval;
retval = c2_read_addr();
while((retval&mask)==0) retval = c2_read_addr();
}
static unsigned char c2_poll_bit_low(unsigned char mask) {
unsigned char retval;
retval = c2_read_addr();
while(retval&mask) retval = c2_read_addr();
}
unsigned char c2_read_flash_block(unsigned int addr, unsigned char * data, unsigned char len) {
unsigned char retval,i;
c2_write_addr(0xB4);
@ -255,22 +262,13 @@ void setup() {
DDRB |= (1<<C2CK_PIN);
C2CK_PORT |= (1<<C2CK_PIN);
// Startup indicator
for(int i = 0; i < 10; i++) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
// pinMode(11, OUTPUT);
// pinMode(12, OUTPUT);
// testing
/*
for(int i=0; i < 100; i++) {
C2CK_PORT &= ~(1<<C2CK_PIN);
delay(50);
C2CK_PORT |= (1<<C2CK_PIN);
digitalWrite(LED, LOW);
delay(50);
}
*/
}
unsigned int i;
@ -289,13 +287,15 @@ unsigned char rx_state_machine (unsigned char state, unsigned char rx_char) {
if(state==1) {
bytes_to_receive = rx_char;
rx_message[rx_message_ptr++] = rx_char;
if (bytes_to_receive==0) return 3;
if(bytes_to_receive==0)
return 3;
return 2;
}
if(state==2) {
rx_message[rx_message_ptr++] = rx_char;
bytes_to_receive--;
if (bytes_to_receive==0) return 3;
if(bytes_to_receive==0)
return 3;
}
return state;
}

Loading…
Cancel
Save