?? lab6.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 + -