Microcontroller Programming with p18f4520: Timers and Inputs, Exercises of Embedded Control Systems

Five c programs for microcontroller pic18f4520. Each program demonstrates the use of timers and inputs in different ways. The first and second programs use timers tmr0 and tmr3 respectively to toggle an output pin. The third program uses a delay function to change an output pin based on an input switch. The fourth program displays the values of tmr1l and tmr1h on two output ports. The fifth program toggles an output pin based on the overflow of tmr1. These programs can be useful for understanding the basics of timer and input operations in microcontroller programming.

Typology: Exercises

2011/2012

Uploaded on 07/26/2012

unknown user
unknown user 🇮🇳

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Question #1
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config BOREN = OFF
#pragma config LVP = OFF
void main(void)
{
TRISAbits.TRISA0=0;
ADCON1=0x0F;
TMR0H=0x41;
TMR0L=0x44;
T0CON=0b10000101;
while(1)
{
if(INTCONbits.T0IF==1)
{
INTCONbits.T0IF=0;
TMR0H=0x41;
TMR0L=0x44;
T0CON=0b10000101;
PORTAbits.RA0=~PORTAbits.RA0;
}
}
}
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Microcontroller Programming with p18f4520: Timers and Inputs and more Exercises Embedded Control Systems in PDF only on Docsity!

#include<p18f4520.h> #pragma config WDT=OFF #pragma config OSC=HS #pragma config BOREN = OFF #pragma config LVP = OFF

void main(void) { TRISAbits.TRISA0=0;

ADCON1=0x0F; TMR0H=0x41; TMR0L=0x44; T0CON=0b10000101;

while(1) { if(INTCONbits.T0IF==1) { INTCONbits.T0IF=0; TMR0H=0x41; TMR0L=0x44; T0CON=0b10000101; PORTAbits.RA0=~PORTAbits.RA0;

} } }

#include<p18f4520.h> #pragma config WDT=OFF #pragma config OSC=HS #pragma config BOREN = OFF #pragma config LVP = OFF

void main(void) { TMR3H=0xF6; TMR3L=0x3c; T3CON=0b00110001; while(1) { if(PIR2bits.TMR3IF==1) { PIR2bits.TMR3IF=0; T3CON=0b00000000; TMR3H=0xF6; TMR3L=0x3c; T3CON=0b00110001;

} } }

#include<p18f4520.h> #pragma config WDT=OFF #pragma config OSC=HS #pragma config BOREN = OFF #pragma config LVP = OFF

void main(void) { unsigned int counter; TRISB=0; TRISD=0; TRISCbits.TRISC0=1; ADCON1=0x0F; TMR1H=0x27; TMR1L=0x10; T1CON=0b10000011; while(1) { PORTB=TMR1L; PORTD=TMR1H;

}//while }

#include<p18f4520.h> #pragma config WDT=OFF #pragma config OSC=HS #pragma config BOREN = OFF #pragma config LVP = OFF

void main(void) { TRISBbits.TRISB7=0; TMR1H=0x7c; TMR1L=0x2a; T1CON=0b00010001;

{ while(1) { if(PIR1bits.TMR1IF==1) { PIR1bits.TMR1IF=0; TMR1H=0x7c; TMR1L=0x2a; T1CON=0b00010001; PORTBbits.RB7=~PORTBbits.RB7; } } } }