lab2.c

来自「PICC 16X Code for study and learning」· C语言 代码 · 共 116 行

C
116
字号

/****************************************************************
*			Hi-Tech workshop exercise Lab2						*
*****************************************************************
* The program will display a binary count value on PORTD (LED)	*
* every delay 200mS												*
*																*
*   Files required:												*
*																*		
*                   lab2.c										*
*					MID_LCD.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"
#include "mid_lcd.h"

//**********************************
//* Function Prototype Declaration
//**********************************


// ================================================================
// **** 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 ); 

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


#define	SW3	RA4
#define SW2	RB0

const char LCD_Msg1[]="Hi-Tech PICC Ex2"; 
const char LCD_Msg2[]=" Up:00  Down:00 "; 
unsigned char i;
unsigned char debounce=0;
unsigned char Up_Count=0;
unsigned char Down_Count=0;

/*****************************
    INITIALIZE SYSTEM
*****************************/

void Init_System(void)
{
	ADCON1=0b00000110;		// Disable A/D Function
	TRISD=0x00;				// Set PortD for Output
	PORTD=0x80;				// Initila LED display = 0x80
	TRISA4=1;				// Set SW2 for input
	TRISE1=1;				// Set SW6 for Input
}

//***************************************
//*             Program Main ( )		*
//***************************************
void main(void)
{
	Init_System();
	OpenLCD();
	LCD_Set_Cursor(0,0);
	putrsLCD(LCD_Msg1);
	LCD_Set_Cursor(0,1);
	putrsLCD(LCD_Msg2);

	while(1)
	{
		if (debounce==0)
			{
				if (!SW3) 
					{
					PORTD++;
					LCD_Set_Cursor(4,1);
					puthexLCD(++Up_Count);
					debounce=30;
					}
				if (!SW2) 
					{
					PORTD--;
					LCD_Set_Cursor(13,1);
					puthexLCD(--Down_Count);
					debounce=30;
					}
			}
		else
			{
				if (SW3 & SW2) 
					{
					debounce--;
					for (i=0;i<50;i++);
					}
				else 
					debounce=30;	
			}		 
	}
	
}


⌨️ 快捷键说明

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