⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lab6.c

📁 PICC 16X Code for study and learning
💻 C
字号:


/****************************************************************
*			Hi-Tech workshop exercise Lab6						*
*****************************************************************
*																*
*   Files required:												*
*																*		
*                   lab6.c										*
*                   cnfig877a.h (Set the Configuration Word)	*
*																*
*                   pic.h        (Hi-Tech file)					*
*																*
*****************************************************************
*																*
*   Notes:														*
*																*
*   Device Fosc -> 16.00MHz (Clock supplied by target)			*
*																*	
*****************************************************************/

#include <pic.h>				// processor if/def file
#include "cnfig877a.h"

//**********************************
//* Function Prototype Declaration
//**********************************
void interrupt isr_Sevr ( void );

// ================================================================
// **** Establish PIC16F877A Configuration Word
// **** == HS Oscillator Mode
// **** == Brown-Out Detect Enabled
// **** == Watch-Dog Timer Off
// **** == Code Protect Off
// **** == Low Voltage Programming Off
// **** == ICD2 Debug Mode On

__CONFIG  ( HS_OSC & BODEN_ON & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON ); 

// =================================================================

volatile unsigned char Long_Count ;
volatile unsigned char Direct_LED ;
volatile unsigned char Dir_Count ;

void main(void)
{
		TRISD=0x00;					// Set output port for LED driver
		PORTD=0b00000001;			// Set b0 of LED is On

		T2CON=0b01111110;			// Timer2 On, Postscale=16, Prescale=16
		TMR2IE=1;					// Enable Timer2 Interrupt
		PEIE=1;						// Set Timer2 for High Priority
		GIE=1;						// Enable High Priority Interrupt
		PR2 = 155;					//(16Mhz/4) [16*16*(155+1)] = 10mS 

		Long_Count=0;
		Direct_LED=0;
		Dir_Count=0;

		while(1);					// Loop Here!
}


//***********************************************
//*  		Interrupt Service Routine			*       
//***********************************************

void interrupt isr_Sevr ( void )
 
{
	TMR2IF=0;							// Clear Timer2 interrupt Flag

	if (Long_Count <=10) Long_Count++;  // 10mS * 10 = 100mS
	else
	{	
		Long_Count=0;					// Time is 100mS, do the function

		if (Direct_LED==0x00)			// Right or Left shift
		{
		 	PORTD<<=1;					// LED left shift
			Dir_Count++;
			if (Dir_Count==7) 			// End of LED position?
			{
				Dir_Count=0;			// Yes, set flag of right shift
				Direct_LED=0x1;
			}
		}
		else
		{
			PORTD>>=1;					// LED right shift
			Dir_Count++;
			if (Dir_Count==7) 
			{
				Dir_Count=0;
				Direct_LED=0x00;
			}
		}
	}		
}								








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -