发新帖本帖赏金 0.10元(功能说明)我要提问
返回列表
打印
[PIC®/AVR®/dsPIC®产品]

PIC18F47Q10小板按键问题

[复制链接]
3483|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Cjy_JDxy|  楼主 | 2019-11-24 21:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
代码如下:
// CONFIG1L
#pragma config FEXTOSC = LP     // External Oscillator mode Selection bits (LP (crystal oscillator) optimized for 32.768 kHz; PFM set to low power)
#pragma config RSTOSC = LFINTOSC// Power-up default value for COSC bits (Low-Frequency Oscillator)

// CONFIG1H
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)

// CONFIG2L
#pragma config MCLRE = EXTMCLR  // Master Clear Enable bit (MCLR pin (RE3) is MCLR)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (Power up timer disabled)
#pragma config LPBOREN = OFF    // Low-power BOR enable bit (Low power BOR is disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled , SBOREN bit is ignored)

// CONFIG2H
#pragma config BORV = VBOR_190  // Brown Out Reset Voltage selection bits (Brown-out Reset Voltage (VBOR) set to 1.90V)
#pragma config ZCD = OFF        // ZCD Disable bit (ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
#pragma config PPS1WAY = ON     // PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)

// CONFIG3L
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF       // WDT operating mode (WDT Disabled)

// CONFIG3H
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC      // WDT input clock selector (Software Control)

// CONFIG4L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection Block 2 (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection Block 3 (Block 3 (00C000-00FFFFh) not write-protected)
#pragma config WRT4 = OFF       // Write Protection Block 4 (Block 4 (010000-013FFFh) not write-protected)
#pragma config WRT5 = OFF       // Write Protection Block 5 (Block 5 (014000-017FFFh) not write-protected)
#pragma config WRT6 = OFF       // Write Protection Block 6 (Block 6 (018000-01BFFFh) not write-protected)
#pragma config WRT7 = OFF       // Write Protection Block 7 (Block 7 (01C000-01FFFFh) not write-protected)

// CONFIG4H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-30000Bh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
#pragma config SCANE = ON       // Scanner Enable bit (Scanner module is available for use, SCANMD bit can control the module)
#pragma config LVP = ON         // Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)

// CONFIG5L
#pragma config CP = OFF         // UserNVM Program Memory Code Protection bit (UserNVM code protection disabled)
#pragma config CPD = OFF        // DataNVM Memory Code Protection bit (DataNVM code protection disabled)

// CONFIG5H

// CONFIG6L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection Block 2 (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection Block 3 (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR4 = OFF      // Table Read Protection Block 4 (Block 4 (010000-013FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR5 = OFF      // Table Read Protection Block 5 (Block 5 (014000-017FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR6 = OFF      // Table Read Protection Block 6 (Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR7 = OFF      // Table Read Protection Block 7 (Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks)

// CONFIG6H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <pic18f47q10.h>

/*
*
*/
unsigned int i;

int main(int argc, char** argv)
{
    TRISE=0x04;
    ADCON0=0;
    while(1)
    {
        if(RE2==0)
            RE0=0;
        else
            RE0=1;
    }
    return (EXIT_SUCCESS);
}
烧写进去,灯一直亮,按键不起作用。大神看看哪有问题?谢谢!

使用特权

评论回复
沙发
Cjy_JDxy|  楼主 | 2019-11-25 09:21 | 只看该作者
版主在吗?

使用特权

评论回复
板凳
xyz549040622| | 2019-11-25 09:23 | 只看该作者
不明觉厉,好歹分享下你程序的想法和电路图呀。

使用特权

评论回复
地板
Cjy_JDxy|  楼主 | 2019-11-25 09:30 | 只看该作者
xyz549040622 发表于 2019-11-25 09:23
不明觉厉,好歹分享下你程序的想法和电路图呀。

RE2接按键,RE0接灯。
按下灯亮,弹起灯灭。

使用特权

评论回复
5
Cjy_JDxy|  楼主 | 2019-11-25 10:51 | 只看该作者
谁给我解决问题,我就打赏。

使用特权

评论回复
6
奔波儿熊| | 2019-11-25 11:32 | 只看该作者
试试看加这两行
TRISE = 0x06;
ANSELE = 0x02;

使用特权

评论回复
7
Cjy_JDxy|  楼主 | 2019-11-25 11:34 | 只看该作者
奔波儿熊 发表于 2019-11-25 11:32
试试看加这两行
TRISE = 0x06;
ANSELE = 0x02;

谢谢!晚上试试。

使用特权

评论回复
8
ynwa| | 2019-11-25 13:58 | 只看该作者
本帖最后由 ynwa 于 2019-11-25 14:00 编辑
Cjy_JDxy 发表于 2019-11-25 09:30
RE2接按键,RE0接灯。
按下灯亮,弹起灯灭。

RE2和模拟输入复用。要作为数字输入,首先需要设置成数字脚(ANSELE寄存器)。RE0作为数字输出,也应该设置为数字脚。

使用特权

评论回复
9
Cjy_JDxy|  楼主 | 2019-11-25 14:23 | 只看该作者
ynwa 发表于 2019-11-25 13:58
RE2和模拟输入复用。要作为数字输入,首先需要设置成数字脚(ANSELE寄存器)。RE0作为数字输出,也应该设 ...

谢谢!好奇怪,我闪灯程序里没设置,灯可以闪。

使用特权

评论回复
10
奔波儿熊| | 2019-11-25 14:39 | 只看该作者
我拿别的板试过了, 需要这么改
TRISE = 0x06;//你的0x04应该也可以
ANSELE = 0x02;//做l输出模拟开着不影响(但最好也关了),但是做输入模拟一定要关
WPUE = 0x04;

使用特权

评论回复

打赏榜单

Cjy_JDxy 打赏了 0.10 元 2019-11-25
理由:很给力!

11
Cjy_JDxy|  楼主 | 2019-11-25 17:05 | 只看该作者
奔波儿熊 发表于 2019-11-25 14:39
我拿别的板试过了, 需要这么改
TRISE = 0x06;//你的0x04应该也可以
ANSELE = 0x02;//做l输出模拟开着不影响 ...

谢谢!我今晚就试。

使用特权

评论回复
12
chuchuda| | 2019-11-26 17:42 | 只看该作者
成功没有,我们也学习一下

使用特权

评论回复
13
Cjy_JDxy|  楼主 | 2019-11-26 18:23 | 只看该作者
chuchuda 发表于 2019-11-26 17:42
成功没有,我们也学习一下

成功了,我都打赏了

使用特权

评论回复
发新帖 本帖赏金 0.10元(功能说明)我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:绿水本无忧因风皱面,青山原不老为雪白头。

553

主题

3530

帖子

19

粉丝