Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by HGH ( 6 years ago )
.h FILE
#ifdef __ASSEMBLER__
/* Assembler-only stuff */
#else
/* C-stuff, define your assembly functions here */
extern "C" void SDIP_init(void);
extern "C" void led_init(void);
/*----------------------------------LED-1----------------------------------------*/
extern "C" void led_1(void);
extern "C" uint8_t SDIP_1(void);
/*----------------------------------LED-2----------------------------------------*/
extern "C" void led_2(void);
extern "C" uint8_t SDIP_2(void);
/*----------------------------------LED-3----------------------------------------*/
extern "C" void led_3(void);
extern "C" uint8_t SDIP_3(void);
/*----------------------------------LED-4----------------------------------------*/
extern "C" void led_4(void);
extern "C" uint8_t SDIP_4(void);
6
.s File
#include <avr/io.h>
#include "Week3_example_SDIP1_LED1.h"
; initilize the Port C's Pin 2~5 since they are connected to switch 1~4
.global SDIP_init
SDIP_init:
ldi r16,0b00000000; Step 1): setting port C pin2~5 as input
out 0x07,r16; 0x07 is the address of DDRC
ldi r16, 0b00111100; Step 1.5): Pull high of the port C pin2~5
out 0x08,r16; 0x08 is the address of PORTC
/*----------------------------------SDIP_1----------------------------------------*/
.global SDIP_1
SDIP_1:
in r24,0x06; Read port C (all 8-bit), PINC address is 0x06
ANDI r24,0b00000100; Only bit2 of PINC (correspnding to pin2) is connected to switche 1.
ret ;Hence using logic operation "AND" to mask out bit0~1 and bit3~7.
;Since the content of R24 is the value to be returened to C.
/*----------------------------------SDIP_2----------------------------------------*/
.global SDIP_2
SDIP_2:
in r24,0x06; Read port C (all 8-bit), PINC address is 0x06
ANDI r24,0b00001000; Only bit2 of PINC (correspnding to pin2) is connected to switche 1.
ret ;Hence using logic operation "AND" to mask out bit0~1 and bit3~7.
;Since the content of R24 is the value to be returened to C.
/*----------------------------------SDIP_3----------------------------------------*/
.global SDIP_3
SDIP_3:
in r24,0x06; Read port C (all 8-bit), PINC address is 0x06
ANDI r24,0b00010000; Only bit2 of PINC (correspnding to pin2) is connected to switche 1.
ret ;Hence using logic operation "AND" to mask out bit0~1 and bit3~7.
;Since the content of R24 is the value to be returened to C.
/*----------------------------------SDIP_3----------------------------------------*/
.global SDIP_4
SDIP_4:
in r24,0x06; Read port C (all 8-bit), PINC address is 0x06
7
ANDI r24,0b00100000; Only bit2 of PINC (correspnding to pin2) is connected to switche 1.
ret ;Hence using logic operation "AND" to mask out bit0~1 and bit3~7.
;Since the content of R24 is the value to be returened to C.
/*----------------------------------SDIP_4----------------------------------------*/
ret
.global led_init
led_init:
ldi r16,0b00111111
out 0x04,r16; set I/O B pin0~5 as output direction
ldi r16,0b11000000
out 0x0A,r16; set I/O D pin6~7 as output direction
ldi r16,0b00000000
out 0x05,r16; send low to all I/O port B's pins including Pin0~5, to turn off LED0~5
out 0x0B, r16; send low to all I/O port D's pins including Pin6~7 to turn off LED6~7
ret
/*----------------------------------LED-1----------------------------------------*/
.global led_1
led_1:
sbi 0x05,1
ret
/*----------------------------------LED-2----------------------------------------*/
.global led_2
led_2:
sbi 0x05,2
ret
/*----------------------------------LED-4----------------------------------------*/
.global led_3
led_3:
sbi 0x05,3
ret
/*----------------------------------LED-5----------------------------------------*/
.global led_4
led_4:
sbi 0x05,4
ret
8
.ino FILE
#include <mechbotShield.h>
#include <USART.h>
#include <avr/io.h>
#include "Week3_example_SDIP1_LED1.h"
int main()
{ uint8_t i;
SDIP_init();
led_init();
initUSART();
/*----------------------------------SDIP_1----------------------------------------*/
i=SDIP_1();
if(i!=0)
{/*printString("\n i=");*/
/*printBinaryByte(i); */
printString("\n Switch 1 is low.");
led_1();
}
else
{/*printString("\n i=");*/
/*printBinaryByte(i); */
printString("\n Switch 1 is\ high.");
}
/*----------------------------------SDIP_2----------------------------------------*/
i=SDIP_2();
if(i!=0)
{/*printString("\n i="); */
/*printBinaryByte(i); */
printString("\n Switch 2 is low.");
led_2();
}
else
{/*printBinaryByte(i); */
printString("\n Switch 2 is high.");
}
/*----------------------------------SDIP_3----------------------------------------*/
i=SDIP_3();
if(i!=0)
{/*printString("\n i=");*/
/*printBinaryByte(i); */
9
printString("\n Switch 3 is low.");
led_3();
}
else
{/*printBinaryByte(i); */
printString("\n Switch 3 is high.");
}
/*----------------------------------SDIP_4----------------------------------------*/
i=SDIP_4();
if(i!=0)
{/*printString("\n i="); */
/*printBinaryByte(i); */
printString("\n Switch 4 is low.");
led_4();
}
else
{/*printBinaryByte(i); */
printString("\n Switch 4 is high.");
}
return;
}
Revise this Paste