是的,从R0到R2改变输出,我认为RA0是有缺陷的。然而,使ADCON1=0x06修复了问题。我爱你Guys微笑:我非常感谢你的帮助,这在过去的一周里让我发疯了。这里是工作代码,参考:/**文件:JavaIs**,创建于2017年6月18日,11:08*///COFIGG,PrimaMaul-FiCc=hs/振荡器选择位(HS振荡器)α-PrAPMA配置,WDTE=OF//看门狗定时器允许位(WDT禁用)EL使能位(PWRT使能)Low Voltage / Prima配置BRONE=//Brown OUT重置允许位(BOR使能)α-PrAPMA配置LVP=OF//L(单电源)在电路串行编程使能位(RB3是数字I/O,MCU上的HV必须用于编程)α-PrAPMA COMPIG CPD= OF//数据EEPROM备忘录RY码保护位(数据EEPROM代码保护关)α·PrimaMac配置WRT=OF//Flash程序存储器写使能位(写保护断开;所有程序存储器可由EECON控制写入)定义了20000000×1的定义,定义了R~rd2;定义E4 rd3定义d4 rd4,定义d6rd6定义d7 rd7定义定义的RC4定义计数器;Car反OSTR(5);易失性A;空中断编码器(if){if X.H.G.(AtnNo.Itf=1){a= OutPoT;if(A==on){计数器(==off){计数器=计数器+1;}} IntercBist.Itf=0;}空主(空隙){Led=on;//状态为OpTythReg=0B90000;//在下降沿ItCONC= 0B10010000;//全局中断和RB0:外部触发设置:外部中断设置ADCON1= 0x06;//设置PATA到数字计数器=10;//变量初始化TrISA=0xFF;//端口E设置为输入TrISB= 0xFF;//端口B设置为输入TISISC=0x00;//端口C设置为输出TrISD=0x00;//端口D设置为输出LCDGIN();/LCD初始化LCDL CUSER();(1){SaveTf(反OSTR),“%.2i”,计数器;LCDSETSt*Curror(1,1);LCDSRead Enter字符串(反OSTR STR);γ-DelayyMS(10);}返回;}
以上来自于百度翻译
以下为原文
Yes did change outputA from RA0 to RE2, I thought RA0 was defective. However, making ADCON1=0x06 fix the problem. I love you guysSmile:
. I really appreciate your help, this has been driving my crazy for the past week. Here is the working code for reference.
/*
* File: interrupt.c
* Author: Jevais
*
* Created on 18 June 2017, 11:08
*/
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include
#include
#include
#define _XTAL_FRQ 20000000
#define on 1
#define off 0
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#define LED RC4
#define outputA RA0
int counter;
char counter_str[5];
volatile A;
void interrupt encoder (){
if (INTCONbits.INTF==1){
A=outputA;
if (A==on) {counter=counter-1;}
else if (A==off) {counter=counter+1;}
}
INTCONbits.INTF = 0;
}
void main(void) {
LED = on; // status led on
OPTION_REG = 0b00000000; // trigger set on falling edge
INTCON = 0b10010000; // global interrupt and RB0:external interrupt set
ADCON1 = 0x06; // set portA to digital
counter = 10; // variable initialised
TRISA = 0xff; // port E set as input
TRISB = 0xff; // port B set as input
TRISC = 0x00; // port C set as output
TRISD = 0x00; // port D set as output
Lcd_Init(); // LCD initialised
Lcd_Clear();
while(1){
sprintf(counter_str, "%.2i",counter);
Lcd_Set_Cursor(1,1);
Lcd_Write_String(counter_str);
__delay_ms(10);
}
return;
}