0% found this document useful (0 votes)
49 views5 pages

File: Newmain.c: V V (R3 / (R1+R3) ) 5 (220 / (220+280) ) 2.2V

This document describes a circuit using a PIC16F877A microcontroller that controls two LEDs by varying the resistance of resistors connected in series to reduce the voltage across each LED to 2.2V and limit the current to 10mA. Resistors R1 and R3 are used to control LED1, while resistors R2 and R4 control LED2. The code uses Timer0 to generate delays and toggle the states of the LEDs by setting the RB3 and RB5 pins high and low in a repeating pattern.

Uploaded by

Lê Minh Hiếu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views5 pages

File: Newmain.c: V V (R3 / (R1+R3) ) 5 (220 / (220+280) ) 2.2V

This document describes a circuit using a PIC16F877A microcontroller that controls two LEDs by varying the resistance of resistors connected in series to reduce the voltage across each LED to 2.2V and limit the current to 10mA. Resistors R1 and R3 are used to control LED1, while resistors R2 and R4 control LED2. The code uses Timer0 to generate delays and toggle the states of the LEDs by setting the RB3 and RB5 pins high and low in a repeating pattern.

Uploaded by

Lê Minh Hiếu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

- PIC16F877A

- LED (2,2V/10mA) x2.


- Tụ gốm 22p x2.
- Thạch anh 20Mhz.
- Điện trở R1=280, R3=220.
- Điện trở R2=280, R4=220.

Vđ=V*( R3 / (R1+R3) ) = 5*( 220 / (220+280) ) =2.2V

- R1 mắc nối tiếp R3 để giảm điện áp qua đèn 1 xuống chỉ còn 2,2V và
dòng 10mA.
- R2 mắc nối tiếp R4 để giảm điện áp qua đèn 2 xuống chỉ còn 2,2V và
dòng 10mA.

/*
* File: newmain.c
* Author: ADMIN
*
* Created on May 18, 2020, 9:40 AM
*/

#include<stdio.h>
#include<stdlib.h>
#include<xc.h>
#include<pic.h>
#define XTAL_FREQ 20000000
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT
enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT
disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR
enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit
Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be
used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection
bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits
(Write protection off; all program memory may be written to by EECON
control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit
(Code protection off)

void delay_timer0 (unsigned int i)


{
while(i--)
{
TMR0 = 100 ;
INTCON.TMR0IF = 0 ;
while(!INTCON.TMR0IF )
}
}
void main()
{

OPTION_REG.TOCS = 0 ; // dem xung noi


OPTION_REG.PSA = 0 ; // bo chia dc sd cho timer0
// chon ti le cho bo chia trc 1:32
OPTION_REG.PS2 = 1 ;
OPTION_REG.PS1 = 0 ;
OPTION_REG.PS0 = 0 ;
TRISB0 = 0X00 ;

while(1)
{ unsigned int dem ;
dem = 4000 ;
if (dem < 1000)
{
RB3 = 0 ;
RB5 = 0 ;
delay_timer0(1000) ;
}
else if (dem >= 1000 && dem < 2000)
{
RB3= 1 ;
RB5 = 1 ;
delay_timer0(1000);
}
else if (dem >= 2000 && dem < 3000)
{
RB3 = 1 ;
RB5 = 0 ;
delay_timer0(1000);
}
else {
RB3 = 0 ;
RB5 = 1 ;
delay_timer0(1000);
}
}
}

You might also like