Low End Microchip PICs C函数

源代码在线查看: flash1.c

软件大小: 2420 K
上传用户: mpeg2000
关键词: Microchip PICs Low End
下载地址: 免注册下载 普通下载 VIP

相关代码

				// FLASH1.C
				//
				// Continually flashes an LED on PORTD.4 in bursts of five flashes.
				//
				// This is intended as a demo routine in presenting the various features
				// of the Serial In Circuit Debugger.
				//
				// Although this was written for a 4.0 MHz clock, the hex file may be used
				// with a target processor having 8.0, 10.0 or 20.0 MHz clock.  Note that
				// the time delays will be 2, 2.5 and 5 times faster.
				//
				// copyright, Peter H. Anderson, Baltimore, MD, Dec 14, '00
				//
				
				#case
				
				#device PIC16F877 *=16 ICD=TRUE
				
				#include 
				
				void flash(byte num_flashes);
				void delay_10us(byte t);
				void delay_ms(long t);
				
				void main(void)
				{
				   while(1)
				   {
				     pspmode = 0;    // make PORTD general purpose IO
				     flash(5);
				     delay_ms(3000);
				   }
				}
				
				void flash(byte num_flashes)
				{
				   byte n;
				   for (n=0; n				   {
				     trisd4 = 0;        // be sure bit is an output
				     portd4 = 1;
				     delay_ms(500);
				     portd4 = 0;
				     delay_ms(500);
				   }
				}
				
				void delay_10us(byte t)
				// provides delay of t * 10 usecs (4.0 MHz clock)
				{
				#asm
				      BCF STATUS, RP0
				DELAY_10US_1:
				      CLRWDT
				      NOP
				      NOP
				      NOP
				      NOP
				      NOP
				      NOP
				      DECFSZ t, F
				      GOTO DELAY_10US_1
				#endasm
				}
				
				void delay_ms(long t)   // delays t millisecs (4.0 MHz clock)
				{
				   do
				   {
				     delay_10us(100);
				   } while(--t);
				}
				
				
				
				
							

相关资源