Question
// Arduino demo program // PORT Arduino smt-pin function what we use it for // label // PORTB.0 0x01 8 12 O CLKO/ICP1 TRIG //
// Arduino demo program
// PORT Arduino smt-pin function what we use it for // label // PORTB.0 0x01 8 12 O CLKO/ICP1 TRIG // PORTB.1 0x02 9 13 I OC1A ECHO // PORTB.2 0x04 10 14 O OC1B LED D3 // PORTB.3 0x08 11 15 O MOSI/OC2A // PORTB.4 0x10 12 16 I MISO // PORTB.5 0x20 13 17 O SCK LED D2 // PORTB.6 0x40 7 x XTAL1 // PORTB.7 0x80 8 x XTAL2
#define SET_DDRB 0x2D // b 0010 1101 #define SET_PORTB 0x00
// PORTC.0 0x01 A0 23 I ADC0 CDS Light sensor // PORTC.1 0x02 A1 24 O ADC1 S1 // PORTC.2 0x04 A2 25 O ADC2 S2 // PORTC.3 0x08 A3 26 O ADC3 X1 // PORTC.4 0x10 A4 27 O ADC4 X2 // PORTC.5 0x20 A5 28 O ADC5 X3 // PORTC.6 0x40 29 x RESET
#define SET_DDRC 0xFE // b 1111 1110 #define SET_PORTC 0x00
// PORTD.0 0x01 0 30 I Rx RX SERIAL Data // PORTD.1 0x02 1 31 O Tx TX SERIAL Data // PORTD.2 0x04 2 32 O INT0 NC // PORTD.3 0x08 3 1 O OC2B/INT1 NC // PORTD.4 0x10 4 2 O XCK/T0 SERVO 0 // PORTD.5 0x20 5 9 O OC0B/T1 SERVO 1 // PORTD.6 0x40 6 10 O OC0A/AIN0 SERVO 2 // PORTD.7 0x80 7 11 O AIN1 SERVO 3
#define SET_DDRD 0xFE // b 1111 1110 #define SET_PORTD 0x00
// ADC6 19 x ADC6 NC // ADC7 22 x ADC7 NC
volatile uint8_t tick; // ++ every 4mS uint8_t tickX;
uint8_t time4mS; uint8_t time100mS; uint32_t time1S;
#define TX_BUF_SIZE 64 #define TX_BUF_MASK 0x3F
#define RX_BUF_SIZE 64 #define RX_BUF_MASK 0x3F
volatile char txBuf[TX_BUF_SIZE]; volatile uint8_t txBufInPtr; volatile uint8_t txBufOutPtr;
volatile char rxBuf[RX_BUF_SIZE]; volatile uint8_t rxBufInPtr; volatile uint8_t rxBufOutPtr;
char cmdBuf[16]; uint8_t cmdBufPtr;
volatile uint16_t servo[4];
volatile uint8_t servoState;
#define S_HIGH 35000 #define S_LOW 45000 #define CENTER 40000
SIGNAL(USART_UDRE_vect){ if(txBufOutPtr == txBufInPtr){ // no more char to output UCSR0B &= ~0x20; } else { // we have more UDR0 = txBuf[txBufOutPtr++]; txBufOutPtr &= TX_BUF_MASK; } }
SIGNAL(USART_RX_vect){ rxBuf[rxBufInPtr++] = UDR0; rxBufInPtr &= RX_BUF_MASK; }
SIGNAL(TIMER1_OVF_vect){ TCCR1B = 0x00; // kill timer1 switch(servoState){ case 0: PORTD &= ~0x10; // kill servo 0 PORTD |= 0x20; // start servo 1
TCCR1A = 0x00; TCNT1 = servo[1]; TIMSK1 = 0x01; // interrupts for timer 1 on TCCR1B = 0x01; // start counting servoState = 1;
break; case 1: PORTD &= ~0x20; // kill servo 1 PORTD |= 0x40; // start servo 2
TCCR1A = 0x00; TCNT1 = servo[2]; TIMSK1 = 0x01; // interrupts for timer 1 on TCCR1B = 0x01; // start counting */ servoState = 2;
break; case 2: PORTD &= ~0x40; // kill servo 1 break; } }
void inline processServos(){ // this is called every 20mS PORTD |= 0x10; servoState = 0; TCCR1A = 0x00; TCNT1 = servo[0]; TIMSK1 = 0x01; // interrupts for timer 1 on TCCR1B = 0x01; // start counting }
SIGNAL(TIMER0_COMPA_vect){ static uint8_t i = 0; PINC = 0x08; tick++; i++;
if(i > 4){ PINC = 0x10; i = 0; processServos(); }
}
void busyWait(){ volatile uint32_t i; for(i=0;i
void outCharOld(char c){ while((UCSR0A & 0x20) == 0); // we don't want to do this UDR0 = c; }
void outChar(char c){ txBuf[txBufInPtr++] = c; txBufInPtr &= TX_BUF_MASK; UCSR0B |= 0x20; }
void printHex4(uint8_t n){ n = n & 0x0F; n = n + '0'; if(n > '9'){ n += 7; }
outChar(n); }
void printHex8(uint8_t n){ printHex4(n >> 4); printHex4(n); }
void printHex16(uint16_t n){ printHex8(n >> 8); printHex8(n); }
void printHex32(uint32_t n){ printHex16(n >> 16); printHex16(n); }
void printStatus(){ printHex8(rxBufInPtr); outChar(' '); printHex32(time1S); outChar(0x0A); }
void printString(char *s){ while(s[0]){ outChar(s[0]); s++; } }
uint8_t getArg1(){ uint8_t n; // convert the cmdBuf[1] cmdBuf[2] to a value return n; }
void processCommand(){ outChar('('); printString(cmdBuf); outChar(')'); outChar(0x0A);
switch(cmdBuf[0]){ case 'a': printString("hit an a"); servo[1] = S_HIGH; break; case 'b': printString("some stuff here");
servo[1] = getArg1 * 256(); break; case 'c': printString("other stuff"); break; case 'd': printString("hello"); break; } }
void processChar(){ char c; c = rxBuf[rxBufOutPtr++]; rxBufOutPtr &= RX_BUF_MASK; if(cmdBufPtr
void process100mS(){
}
void process1S(){ static uint8_t i=0; printStatus(); i++; if(i & 0x01){ servo[0] = S_HIGH; } else { servo[0] = S_LOW; } }
int main(){ uint16_t i; DDRB = SET_DDRB; DDRC = SET_DDRC; DDRD = SET_DDRD; PORTB = SET_PORTB; PORTC = SET_PORTC; PORTD = SET_PORTD;
// tick timer setup TCCR0A = 0x02; TCCR0B = 0x04; // divide by 8 OCR0A = 250; TIMSK0 = 0x02; SREG |= 0x80; // setup uart UBRR0H = 0; UBRR0L = 103; UCSR0B = 0x98; // 1001 1000
tick = 0;
i = 0;
time1S = 0; servo[0] = CENTER; servo[1] = CENTER; servo[2] = CENTER; servo[3] = CENTER;
while(1){ PINC = 0x20;
if(tick != tickX){ time4mS++; tickX++; if(time4mS > 24){ time100mS++; time4mS = 0; process100mS(); if(time100mS > 9){ time1S++; time100mS = 0; process1S(); } } }
while(rxBufInPtr != rxBufOutPtr){ processChar(); } } // end of while(1) }
Fix the getArg function so that when called returns the converted value from the cmdBuf[1] and cmdBuf[2 Add a printHex8 with the returned value and send me a screen shot of the working program. Fix the getArg function so that when called returns the converted value from the cmdBuf[1] and cmdBuf[2 Add a printHex8 with the returned value and send me a screen shot of the working program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started