Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Based on the wiring above write initialization instructions for an ATtiny24 t

ID: 2080851 • Letter: 1

Question

1) Based on the wiring above write initialization instructions for an ATtiny24 to configure input and output pins. (Notice that all inputs/outputs are connected to Port A. Also notice that some inputs have positive, some negative logic; some have external, some need internal pullups.)

2) Write an assembly program to implement the logic for the alarm system above:
If the sensor detects an alarm condition both the light and the horn should turn on. The lightand horn should turn off if the alarm condition disappears. The horn should also turn off ifthe ‘Hush” pushbutton is pushed. Both outputs should turn on while the “Test” pushbutton ispushed.
You may use any bit-checking method (or a combination of methods) of your choice

5 V 5V PRO d2 Reset PB1 3 PB20 5 TPA7 d 6 6- 7 Alarm FX Alarm light horn 14 ND 13 HPA0 12 HPA1 11 PA2 10 PA33 PA4 Alarm Sensor 5 V 5 V Test Hush 5 V Enable

Explanation / Answer

1) The following program is written in CodeVision

Initialization Code:

#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
DDRA=(1<<DDA7) | (1<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
PORTA=(1<<PORTA7) | (1<<PORTA6) | (0<<PORTA5) | (1<<PORTA4) | (1<<PORTA3) | (1<<PORTA2) | (1<<PORTA1) | (1<<PORTA0);

2) Bitwise reading of the ATtiny24 pins

while (1)
{
if((PINA&0x03)==1)
PORTA=0xC0;
else
if((PINA=0x06)==1)
PORTA=0x00;
else
if((PINA=0x24)==1)
PORTA=0xC0;
}

The Complete Program for the above question is:

#include <tiny24.h>
void main(void)
{
#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
DDRA=(1<<DDA7) | (1<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
PORTA=(1<<PORTA7) | (1<<PORTA6) | (0<<PORTA5) | (1<<PORTA4) | (1<<PORTA3) | (1<<PORTA2) | (1<<PORTA1) | (1<<PORTA0);
while (1)
{
if((PINA&0x03)==1)
PORTA=0xC0;
else
if((PINA=0x06)==1)
PORTA=0x00;
else
if((PINA=0x24)==1)
PORTA=0xC0;
}
}