• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
Since any PORTB pin is able to source a max. of 20mA per pin with PORTB capable of sourcing a max- imum total current of 100mA, hence we can use PORTB to drive LEDdisplay directly. As shown in the circuit, 8 LEDs are connected to PORTB with each120 Ohm current limiting resistor Example to drive 8 LEDS/************************************************* ** COPYRIGHT (c) Blitzlogic Sdn. Bhd. ** Author : Abraham Wong 21/1/2000 ** ** example of using WHILE loop construct ** to drive 8 LEDS connected to port B ** *************************************************/#include <16c84.h>#USE DELAY( CLOCK=4000000 ) /* Using a 4 Mhz clock */#FUSES XT,NOWDT,NOPROTECT,NOPUT/* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */#byte port_b=6 /* define the location of register port_b */
 
main(){byte cnt; value;set_tris_b(0); /* set port_b to be outputs */port_b = 0; /* initialize All port_b outp/uts to be zero */value = 0x01;while( TRUE ){ /* forever loop using WHILE construct */cnt = 0;while ( cnt<8 ){ port_b = value;DELAY_MS(1000);value = value << 1; /* shift left will put 0x01, 0x02, 0x04, 0x08, 0x10 */cnt++; /* 0x20, 0x40, 0x80 to port_b */}}}EXERCISESModify the above program to displaythe following sequence : -LED1 and LED8 turn on, 1 sec delay;LED2 and LED7 turn on, 1 sec delay;LED3 and LED6 turn on, 1 sec delay;LED4 and LED5 turn on, 1 sec delay;Loop back & Repeat again forever 
 
TWO 7 SEGMENT LED & 2 SWITCHESSince we can source a maximum of 20mA per pin for PORTB and total maximumsource current of PORTB is 100mA, hence we can use PORTB to drive LED displaydirectly. As shown in the circuit, 2 common cathode 7-segment LEDs are connected toPORTB with 120 Ohms current limit- ing resistor. Each segment of two LED are tied in parallel to P1. Q1 and Q2 are activated by logic high of PA0 and PA1 which switch onground to the respective common cathode pins. PA2 and PA3 pin are use to read theinputs S1 or S2 switches.The following code, 7-SEG.C demonstrate how to drive two 7-segment LEDs. The program first display digits on the Left LEDs and counts from 0 to 9 with a delay of 1second between each digit. Then it switches to the Right LED and repeats the sametasks and then the whole sequence is repeated all over again from the beginning.Example to drive two 7-Segment LEDs/****************************************** COPYRIGHT (c) Blitzlogic Sdn. Bhd.* Author : Abraham Wong 21/1/2000** example of using FOR loop to drive* two 7-Segment LEDs
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...