gpt4 book ai didi

c - pic 16f84a 计时器/计数代码未按预期运行

转载 作者:太空宇宙 更新时间:2023-11-04 04:02:19 25 4
gpt4 key购买 nike

我基本上是在学习 pic16f84a 微 Controller 上的 pic 外部中断。基本上我想计算每次按下连接到引脚 B0 (RB0/T0CKI) 的按钮并显示来自七段显示器的结果。我正在使用 hitech c 编译器。

#include<htc.h>
__CONFIG(WDTE_OFF& PWRTE_OFF & CP_OFF);
char get7SegmentCode(char value)
{
switch(value)
{
case 0b00000000:
return (char)0b00111111 ; //0 code
case 0b00000001:
return (char)0b00110000 ; //1 code
case 0b00000010:
return (char)0b01011011 ; //2 code
case 0b00000011:
return (char)0b010011111 ; //3 code
default:
return (char)0b00000000 ; //all code
}
}
void main()
{
//declare portb for output and porta upper 4 pins for output and lower 4 for input
TRISA=0b00001111;
TRISB=0b00000000;
CLRWDT();//clear watchdog timer
TMR0=0;
OPTION_REG = 0b00111000;//RBPU:PORTB pull-ups are disabled,
//INTEDG:Interrupt on falling edge of RB0/INT pin
//T0CS:Transition on RA4/T0CKI pin
//T0SE:Increment on high-to-low transition on RA4/T0CKI pin
//PSA:Prescaler assigned to the WDT
while(1)
{
char timerval= TMR0;//read tmr0 into variable
char restrictedtimerval= timerval & 0x0f;//force upper 4bits to zero to restrict value to 0 - f
PORTB= get7SegmentCode(restrictedtimerval);
}
}

不幸的是,当我在 proteus vsm 中模拟此代码时,无论我按下开关多少次,七段显示器都只显示“0”。为什么会这样?PS:这是我的电路。 circuit

最佳答案

Pin RA4/T0CKI 是端口 A 的第五位,名为 RA4。所以你的启动码一定是

TRISA=0b00011111;

代替

TRISA=0b00001111;

关于c - pic 16f84a 计时器/计数代码未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10285924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com