led.c  



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 */
           }
        }
     }


Navigation Bar

tech_support@blitzlogic.com