Escolar Documentos
Profissional Documentos
Cultura Documentos
Project 1
Project title: Simple flashing LED
Project description: An LED is connected to one of the port pins of a PIC microcontroller. The LED is flashed continuously with 1-s interval. Hardware: This project is so simple that any type of PIC microcontroller can be used. As shown in Figure 5.1, a PIC16F84 type microcontroller is chosen for this project. Bit 0 of PORTB (RB0) is connected to a small LED through a current-limiting resistor. The voltage drop across an LED is approxi- mately 2 V. Assuming an LED current of 10 mA, the value of the resistor can be calculated as R=V/I= 5 - 2 10 mA = 0.3 K
Flow diagram:
the nearest value is 330 . The software consists of an indefinite loop where the LED is turned on and off inside this loop. The flow diagram of the software is shown in Figure 1.
Picbasic code:
Device 16F877A XTAL=4 Output PORTB Symbol led = PORTB.0 loop: High led DelayMS 1000
Project 2
Project title: Complex flashing LED
Project description: An LED is connected to one of the port pins of a PIC microcontroller. The LED is flashed continuously as in the following sequence: 3 flashes with 250ms interval between each flash. 2 s delay. 3 flashes with 250ms interval between each flash
BEGIN
I=0
Turn on LED
I=I+1
No
If I=3
Figure 2
Picbasic code :
Dim Cnt As Byte ' Declare Cnt as a byte
' START OF MAIN PROGRAM Output PORTB ' Set PORTB pins as outputs AGAIN: For Cnt =1 To 3 PORTB.0 =1 ' Turn ON LED PAUSE 250 ' Wait 250ms PORTB.0 =0 ' Turn OFF LED PAUSE 250 'Wait 250ms Next Cnt PAUSE 2000 ' Wait 2 seconds GoTo AGAIN ' Repeat End ' End of program
Project 3
Project title: Project description: Binary counting LEDs In this project, 8 LEDs are connected to PORTB of a PIC microcontroller. When the project is started (or when reset), the LEDs count in binary with a 250 ms delay between each count as shown in Figure 5.19. The count goes from 0 (binary 00000000) to 255 (binary 11111111) and then repeats forever.
. .
Flow diagram: The flow diagram of the project is shown .At the beginningof the program the I/O direction is specified. A byte variable called Cnt is used as the loop variable and it is incremented by one every 250 ms. When Cnt reaches 255 it overflows and takes the next value 0 and this process is repeated forever.
BEGIN
Cnt=0
250ms Delay
Cnt=Cnt+1
Project 4
Project title: Project description: Left scrolling LEDs In this project, 8 LEDs are connected to PORTB of a PIC microcontroller. When the project is started (or when reset), the LEDs scroll to the left with a 250 ms delay between each output as shown in Figure 4. When the left-most LED (bit 7) is lit, the next LED lit is the right-most LED (bit 0). This process is repeated forever.
Figure 4
Flow diagram: The flow diagram of the project is shown . At the beginning of the program the I/O direction is specified. A byte variable called Cnt is used as the loop variable and it is shifted left by one digit at every iteration of the loop. When the value of Cnt is 128 (left-most LED is on), it is re- initialised back to 1. A 250 ms delay is used between each output.
BEGIN
Cnt
Device 16F877A XTAL=4 LCD_INTERFACE 4 LCD_LINES 2 LCD_DTPIN PORTD.4 LCD_RSPIN PORTC.0 LCD_ENPIN PORTC.1 Dim t1 As Float Dim t2 As Float Dim ref As Float Dim n As Byte n=4 ""number of sections of revolution"" Input PORTB.1 Symbol pulse=PORTB.1 Input PORTB.2 Input PORTB.3 Input PORTB.4 Symbol r1=PORTB.2 Symbol r2=PORTB.3 Symbol r3=PORTB.4 If r1=1 Then ref=50.00 Print "50rpm" ElseIf r2=1 Then ref=100.00 Print "100rpm" ElseIf r3=1 Then ref=150.00 Print "150rpm" Else ref =0 Print "stopped" EndIf t1=0 t1=Counter pulse,10 t2=t1*100.0/4 Print "freq=",@t2 DelayMS 10 Print Cls