Rewrite HW 1 program. Incorporate the IRQ interrupt to reset the clock #include
ID: 3562018 • Letter: R
Question
Rewrite HW 1 program. Incorporate the IRQ interrupt to reset the clock
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include "main_asm.h" /* interface to the assembly module */
int i,j,k,l; void main() {
DDRB=0b11111111; // sets PORT B as an output
DDRJ=0b11111111; // sets PORT J as an output
DDRP=0b11111111; // sets PORT P as an output
PTJ=0b00000000; // disables LEDs
while(1){
for(i=0;i<10;i++)
for(j=0;j<10;j++)
for(k=0;k<10;k++)
for(l=0;l<6;l++){
seg7dec(l,3);
ms_delay(10);
seg7dec(k,2);
ms_delay(10);
seg7dec(j,1);
ms_delay(10);
seg7dec(i,0);
ms_delay(10);
}
}
}
Explanation / Answer
const COM1_Base = $3F8; COM2_Base = $2F8; LCR_Offset = $03; Latch_Low = $00; Latch_High = $01; procedure SetBaudRate(NewRate: Word); var DivisorLatch: Word; begin DivisorLatch := 115200 div NewRate; Port[COM1_Base + LCR_Offset] := Port[COM1_Base + LCR_Offset] or $80; {Set DLAB} Port[COM1_Base + Latch_High] := DivisorLatch shr 8; Port[COM1_Base + Latch_Low] := DivisorLatch and $FF; Port[COM1_Base + LCR_Offset] := Port[COM1_Base + LCR_Offset] and $7F; {Clear DLAB} end; function GetBaudRate: Integer; var DivisorLatch: Word; begin Port[COM1_Base + LCR_Offset] := Port[COM1_Base + LCR_Offset] or $80; {Set DLAB} DivisorLatch := (Port[COM1_Base + Latch_High] shl 8) + Port[COM1_Base + Latch_Low]; Port[COM1_Base + LCR_Offset] := Port[COM1_Base + LCR_Offset] and $7F; {Clear DLAB} Result := 115200 div DivisorLatch; end;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.