Question: #include / * * * * * * * * * * * * * * * * * * * * * * *

#include
/**************************************************************
** Author: Ronald Kikoyo
*
* Program Title: - Flashing a LED
*
* Program File Name:
*
* Microprocessor B
*
*Spring
*
*
***************************************************************/
void delay_20ms(void)
{
const int D20ms =1150; // Declare a Constant for 20 ms Delay
int i;
for (i =0; i < D20ms; i++);
return;
}
void PIO_Config(void); //prototype
void
Second_Timer2_Config(void);
// PIC24HJ32GP202 Configuration Bit Settings
// FBS
#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // 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 write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
// FOSCSEL
#pragma config FNOSC = FRC // Oscillator Mode (Internal Fast RC (FRC))
#pragma config IESO = OFF // Internal External Switch Over Mode (Start-up device with user-selected oscillator source)
// FOSC
#pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = ON // OSC2 Pin Function (OSC2 pin has digital I/O function)
#pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration (Allow Multiple Re-configurations)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)
// FWDT
#pragma config WDTPOST = PS512// Watchdog Timer Postscaler (1:512)
#pragma config WDTPRE = PR128// WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)
// FPOR
#pragma config FPWRT = PWR16// POR Timer Value (16ms)
#pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins)
// FICD
#pragma config ICS = PGD1// Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)
/************** END --- Configuration Word *********************/
int i, j, k;
int main()
{
k =1 ;//start from LED1
for (i =0;i<255;i++)
for (j =0; j <129;j++);
PIO_Config();
Second_Timer2_Config();
switch (k)
while(1)// Loop Forever
{
T2CONbits.TON =1; // Start 32-bit Timer
while(0==_RB13)//switch
while(IFS0bits.T3IF ==0);
delay_20ms();
case 1:
_LATB14=_LATB14^1; //Toggle LED
break;
delay_20ms();
case 2:
_LATB13=_LATB13^1; //Toggle LED
break;
delay_20ms();
case 3:
_LATB15=_LATB15^1; //Toggle LED
break;
delay_20ms();
case 4:
_LATB12=_LATB12^1; //Toggle LED
break;
delay_20ms();
case 5 :
_LATB11=_LATB11^1; //Toggle LED
break;
delay_20ms();
case 6:
_LATB10=_LATB10^1; //Toggle LED
break;
delay_20ms();
case 7:
_LATB2=_LATB2^1; //Toggle LED
break;
IFS0bits.T3IF =0;
}
k =(k +0)%8;//increment
//*** END OF While (1==1) LOOP
}
/******** END OF main ROUTINE ***************************/
/*************32bit Timer ISR ***************************************/
void __attribute__((__interrupt__, no_auto_psv))_T3Interrupt(void)
{
int flag =0 ;
if ( flag ==0)
{
LATBbits.LATB2=1;
}
else
{
if ( flag ==1)
{
LATBbits.LATB2=0;
}
flag = flag ^1; // Toggle flag
_T3IF =0; // clear the interrupt flag
}
}
/********************************************************************/
void PIO_Config(void)
{
/************ PIO config ***********/
//RB13-- configure as a low true op with internal pull-up enabled
_ODCB13=0; // Disable open drain
_TRISB13=0; // Config RB13 as input
_PCFG11=1; // Config RB13(AN11) for digital mode
_CN13PUE =1; // Enable pull-up on RB13
_ODCB14=0; // Disable open drain
_TRISB14=0; // Config RB14 as output
_PCFG10=1; // Config RB14(AN10) for digital mode
_LATB14=0; // RB14 initial condition: low
_ODCB15=0; // Disable open drain
_TRISB15=0 ; // Config RB15 as input
_LATB15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!