



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
PIC24, Assembly Language, Arithmetic, Overflow, Indirect Addressing, Stack Frame, Weak Internal Pullup, Open Drain Output, Processor, Microcomputers, Exam Papers, Dr Jeff Jackson, Department of Electrical and Computer Engineering, University of Alabama, United States of America.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




ECE383 Sample questions for Exam #2 The exam will be open book/notes.
The exam will focus on material from lecture 5 through lecture 8, slide 25. Knowledge from earlier lectures (1-4) may be required, but will not be the focus of the exam questions.
uint32 i, j, k; int32 x, y, z;
i=j+k; x=y-z;
int32 r, s; int16 t;
if(r<10) r++; s=(int32) t;
// i=j+k; mov j,w mov j+2,w mov k,w mov k+2,w add w0,w2,w addc w1,w3,w mov w0,i mov w1,i+
// x=y-z; mov z,w mov z+2,w mov y,w mov y+2,w sub w0,w2,w subb w1,w3,w mov w0,x mov w1,x+
//if(r<10) r++; mov r,w mov r+2,w mov #9,w mov #0,w sub w2,w0,w subb w1,w3,w bra gt,end_if mov r,w mov r+2,w add w2,#1,w addc w2,#0,w mov w2,r mov w3,r+ end_if:
// s=(int32) t; mov t,w clr w btsc w0,# setm w mov w0,s mov w1,s+
0xFF+0x01=0x
0x7F+0x01=0x
V=C (^) MSB xor C (^) MSB-
int16 i, j, k; int16* p_i; i=0x4000; j=0xFFFF; p_i=&i; k=*p_i;
Give the values of the following memory locations after all the instructions have executed. Complete all cells in the table.
Give the assembly language implementation of the above C code. You must use register indirect addressing to implement *p_i.
mov #0x4000,w mov w0,i setm w mov w0,j mov #i,w mov w0,p_i mov p_i,w
13: int8 i, j; 14: i=5; 02B6 B3C050 mov.b #0x5,0x 02B8 984710 mov.b 0x0000,[0x001c+1] 15: j=my_sub(i); 02BA 90401E mov.b [0x001c+1],0x 02BC 07FFE9 rcall 0x 02BE 784F00 mov.b 0x0000,[0x001c] 16: return 0; 02C0 EB0000 clr.w 0x 17: } 02C2 FA8000 ulnk 02C4 060000 return
When performing write operations to a pin on the PIC24, the LATx and PORTx function the same (i.e. they both write to the LATx register). When performing reads, a LATx read reads from the LATx register while a PORTx read is directly from the pin.
The weak internal pullup capability is provided so that an external pullup resistor is not needed on pins with CNy functionality. The open drain output allows an external pullup resistor to be used to pull output pins up to logic ‘1’ where the output voltage may be something other than the typical +3.3V.
The MCLR# pin on the PIC24 processor is used to reset that processor when the pin is asserted low.
a) Write an inline macro named CONFIG_SW1() that, when used, would correctly configure RB12 as a digital input as shown.
inline void CONFIG_SW1() { CONFIG_RB12_AS_DIG_INPUT(); ENABLE_RB12_PULLUP(); }
b) Write an inline macro named CONFIG_LED1() that, when used, would correctly configure RB13 as a digital output as shown.
#define CONFIG_LED1() CONFIG_RB13_AS_DIG_OUTPUT()
c) Write an inline macro named CONFIG_LED2() that, when used, would correctly configure RB14 as a digital output as shown.
#define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()
d) What is the purpose of the two resistors in series with LED1 and LED2?
They function as current limiting resistors so that the maximum current source/sink for the PIC24 processor will not be exceeded.
e) Write a C program that would use the macros defined above and would alternate lighting LED1 and LED2 every time SW1 is pressed.
#define LED1 _LATB #define LED2 _LATB #define CONFIG_LED1() CONFIG_RB13_AS_DIG_OUTPUT() #define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()
inline void CONFIG_SW1() { CONFIG_RB12_AS_DIG_INPUT(); ENABLE_RB12_PULLUP(); }
#define SW1 _RB #define SW1_PRESSED() SW1== #define SW1_RELEASED() SW1==
main() { CONFIG_SW1(); CONFIG_LED1(); CONFIG_LED2(); LED1=0; LED2=0; while(1) { while(SW1_RELEASED()); DELAY_MS(15); while(SW1_PRESSED()); DELAY_MS(15); LED1=1; LED2=0; while(SW1_RELEASED()); DELAY_MS(15); while(SW1_PRESSED()); DELAY_MS(15); LED1=0; LED2=1; } }