找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1627|回复: 2
打印 上一主题 下一主题
收起左侧

PIC12F675单片机奇怪问题

[复制链接]
跳转到指定楼层
楼主
ID:206067 发表于 2019-1-13 02:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序目的是实现上电灯就亮”输出1“ 定时后”输出0“

#include<pic.h>

#include <xc.h>
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF         // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)

#define KEY GP3

unsigned char count=0;
unsigned char miao=0;
unsigned char fen=0;

void main()
{
    OSCCAL=0b00000100;//intside RC
    TRISIO=0b00001000;//IO方向设置
    OPTION_REG=0b00000111;//分频比1:256
    TMR0=0;
    GP0=1;
  //  GP1=GP2=GP4=GP5=0;  写进这行灯就一直不亮,不写就是正常的
   while(1)
        {
            if(TMR0==180)//50ms
            {
                TMR0=0;
                count++;
                if(count==20)//1秒定时
                {
                    miao++;
                    count=0;
                    if(miao==5)
                    {
                        miao=0;
                        GP0=0;
                    }
                }

            }
       }
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:206067 发表于 2019-1-21 11:35 | 只看该作者
有人知道吗
回复

使用道具 举报

板凳
ID:138119 发表于 2019-1-27 11:16 | 只看该作者
印象中我也遇到过类似问题,很久了,记得可能是编译器优化级别的问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表