Question: #include / * * * * * * * * * * * * * * * * * * * * * * *
#include
Author: Ronald Kikoyo
Program Title: Flashing a LED
Program File Name:
Microprocessor B
Spring
void delaymsvoid
const int Dms ; Declare a Constant for ms Delay
int i;
for i ; i Dms; i;
return;
void PIOConfigvoid; prototype
void
SecondTimerConfigvoid;
PICHJGP Configuration Bit Settings
FBS
#pragma config BWRP WRPROTECTOFF Boot Segment Write Protect Boot Segment may be written
#pragma config BSS NOFLASH Boot Segment Program Flash Code Protection No Boot program Flash segment
FGS
#pragma config GWRP OFF General Code Segment Write Protect User program memory is not writeprotected
#pragma config GSS OFF General Segment Code Protection User program memory is not codeprotected
FOSCSEL
#pragma config FNOSC FRC Oscillator Mode Internal Fast RC FRC
#pragma config IESO OFF Internal External Switch Over Mode Startup device with userselected oscillator source
FOSC
#pragma config POSCMD NONE Primary Oscillator Source Primary Oscillator Disabled
#pragma config OSCIOFNC ON OSC Pin Function OSC pin has digital IO function
#pragma config IOLWAY OFF Peripheral Pin Select Configuration Allow Multiple Reconfigurations
#pragma config FCKSM CSDCMD Clock Switching and Monitor Both Clock Switching and FailSafe Clock Monitor are disabled
FWDT
#pragma config WDTPOST PS Watchdog Timer Postscaler :
#pragma config WDTPRE PR WDT Prescaler :
#pragma config WINDIS OFF Watchdog Timer Window Watchdog Timer in NonWindow mode
#pragma config FWDTEN OFF Watchdog Timer Enable Watchdog timer enableddisabled by user software
FPOR
#pragma config FPWRT PWR POR Timer Value ms
#pragma config ALTIC OFF Alternate IC pins IC mapped to SDASCL pins
FICD
#pragma config ICS PGD Comm Channel Select Communicate on PGCEMUC and PGDEMUD
#pragma config JTAGEN OFF JTAG Port Enable JTAG is Disabled
END Configuration Word
int i j k;
int main
k ;start from LED
for i ;i;i
for j ; j ;j;
PIOConfig;
SecondTimerConfig;
switch k
while Loop Forever
TCONbits.TON ; Start bit Timer
whileRBswitch
whileIFSbits.TIF ;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
delayms;
case :
LATBLATB; Toggle LED
break;
IFSbits.TIF ;
k k ;increment
END OF While LOOP
END OF main ROUTINE
bit Timer ISR
void attributeinterrupt noautopsvTInterruptvoid
int flag ;
if flag
LATBbits.LATB;
else
if flag
LATBbits.LATB;
flag flag ; Toggle flag
TIF ; clear the interrupt flag
void PIOConfigvoid
PIO config
RB configure as a low true op with internal pullup enabled
ODCB; Disable open drain
TRISB; Config RB as input
PCFG; Config RBAN for digital mode
CNPUE ; Enable pullup on RB
ODCB; Disable open drain
TRISB; Config RB as output
PCFG; Config RBAN for digital mode
LATB; RB initial condition: low
ODCB; Disable open drain
TRISB ; Config RB as input
LATB
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
