//-----------------------------------------------------------------
// 名称: RB端口电平变化中断控制两位数码管开关、加减显示
//-----------------------------------------------------------------
// 说明: 本例与此前的K1~K4控制两位数码管开、关、加、减的程序功能
// 类似,但本例用RB端口电平变化中断程序实现.
//
//-----------------------------------------------------------------
#include <pic.h>
#define INT8U unsigned char
#define _XTAL_FREQ 1000000UL
//按键定义
#define K1_DOWN() (RB4 == 0)
#define K2_DOWN() (RB5 == 0)
#define K3_DOWN() (RB6 == 0)
#define K4_DOWN() (RB7 == 0)
INT8U count = 0; //显示计数初值为0
INT8U show_on = 1; //显示开关标志
//数字0~9的共阴数码管段码表
const INT8U SEG_CODE[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
//-----------------------------------------------------------------
// 数码管显示
//-----------------------------------------------------------------
void display()
{
if(!show_on)
{
PORTC=0x00;PORTD=0xFF;return;
}
PORTD=0xFF;
PORTC=SEG_CODE[count/10];
PORTD=~(1<<0);
__delay_ms(2);
PORTD=0xFF;
PORTC=SEG_CODE[count%10];
PORTD=~(1<<1);
__delay_ms(2);
}
//-----------------------------------------------------------------
// 延时函数
//-----------------------------------------------------------------
void delayms(INT8U x)
{
for (INT8U i = 0; i < x; i++)
for (INT8U j = 246; j > 0; j--) NOP();
}
//-----------------------------------------------------------------
// 主程序
//-----------------------------------------------------------------
void main()
{
INT8U Recent_Key=0xFF;
TRISC=0x00;TRISD=0x00;
PORTC=0xFF;PORTD=0xFF;
GIE=1;
RBIE=1;
TRISB=0xFF;
RBPU=0;
while(1)display();
}
//-----------------------------------------------------------------
// RB端口电平变化中断处理函数
//-----------------------------------------------------------------
void interrupt RB_Port_Change_ISR()
{
if (RBIF==1)
{
delayms(5);
if (K1_DOWN())show_on=1;
else if(K2_DOWN())show_on=0;
if(show_on && K3_DOWN())
{
if(count<99)count++;
}
else if (show_on && K4_DOWN() )
{
if (count !=0)count--;
}
RBIF=0;
}
}
Build E:zzg 1 Foundation13 RB Level Change Interrupt Control 2Bits-SEGDSYC16RB Level Change Interrupt Control 2Bits-SEGDSY for device 16F877A
Using driver C:Program Files (x86)HI-TECH SoftwarePICC9.83inpicc.exe
Make: The target "E:zzg 1 Foundation13 RB Level Change Interrupt Control 2Bits-SEGDSYC16main.p1" is out of date.
Executing: "C:Program Files (x86)HI-TECH SoftwarePICC9.83inpicc.exe" --pass1 "E:zzg 1 Foundation13 RB Level Change Interrupt Control 2Bits-SEGDSYC16main.c" -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [192] E:zzg 1 Foundation13 RB Level Change Interrupt Control 2Bits-SEGDSYC16main.c; 62.1 undefined identifier "RBPU"
********** Build failed! **********
此帖出自
小平头技术问答
一周热门 更多>