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

I need to convert this assembly code into C. This is for the chip: PIC18f1220, t

ID: 3731866 • Letter: I

Question

I need to convert this assembly code into C. This is for the chip: PIC18f1220, thank you

p=18F1220 hex WDT=OFF, LVP=OFF, PORTA PORTE TRISA TRISB ADCONL list radix config ; Set proces3or type : Sets the default radix for data exp. OSC OxFBO 0xF81 OxF92 0xF93 OxFC1 INT 102 :Disable Watchdog timer, Low V. Prog, and RA6 as a clock = define #de f i ne #de fine tdefine #define 13 17 COUNT LASTIN INPUT TEMP 0x080 0x081 0x082 0x083 equ equ org 0x000 ; Set the program origin (start) to absolute 0x000 Initialize all I/o port:s CLRE CLRF MOVLW PORTB 0x7F ADCON1 0x00 TRISB : Initialize PORTB ; Set all A/D Converter Pins as ; digital I/o pina : Value used to initialize data direction : Set Port B RB as outputs ; Value used to initialize data direction ; Set Port A Pin 0 RA as input MOVLW 30 MOVLW TRISA 0x00 COUNT LASTIN MOVLW : COUNTWREG ; LAST IN -WREG MOVWE 35 Loop: MOVE XORWE ANDLW PORTA, INPUT INPUT, 0 LASTIN, O INPUTPORTA ; W- PORTA 40 W-W ANDSS 0x1 42 INPUT, LAST IN ; LASTIN=PORTA TEMP TEMP, 0 IncL LOop TEMP- ; If TEMP = 0 Then Skip Next Command MOVWE BTFSC CALL GOTO 48 4 9 50 IncL: MOVE COUNT, 0 :WCOUNT ADDLW ; COUNT = W ; PORTB =w COUNT 52 PORTB

Explanation / Answer

given below code is the c implemetation of given code

#include"htc.h" // includes pic.h and other sub headers
volatile unsigned int     w = 0;
volatile unsigned int     count = 0;
volatile unsigned int     lastin = 0;
void main() {
PORTB = 0;//Initialize output
while (1) {
unsigned int input=PORTA;       //input of PORTA AS input variable
w=input;      
w=w^lastin;       //w XOR lastin
w=w&1;       //w AND 1
lastin=input;
unsigned int temp=w;
if(temp!=0)
{
   w=count;
   w=w+1;
   count=w;
   portb=w;       //SENDING VALUE OF W TO OUTPUT PORT
   break;
}
else{
   continue;
}

}
}

although code is preety self explainatory as i used comments , if you have some doubt please refer standard c syntex.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote