搜索
bottom↓
回复: 11

请教关于PIC12F675

[复制链接]

出0入0汤圆

发表于 2010-8-30 14:40:35 | 显示全部楼层 |阅读模式
在使用PIC12F675时,发现程序下载后无法运行,不知道是什么原因引起的!!
请各位高手指点!
谢谢!
编译器为MPLAB IDE v8.53,HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.70
软件仿真都可以的,不知道究竟是什么原因,并且在循环中不可以设置断点。
以下为源程序:


源程序ourdev_578772.rar(文件大小:21K) (原文件名:GPIO.rar)



#include "pic.h"

__CONFIG(0x0044);
//高门槛电压,取消MCRL,将GP3配置为数字IO,程序保护,数据区保护,看门狗停止,BOD使能,上电延时定时器启动,内部RC晶体

//CONFIG 寄存器  BG1 BG0 — — — CPD CP BODEN MCLRE PWRTE WDTE F0SC2 F0SC1 F0SC0
//               门槛电压    数据保护                              晶体选择

                           晶体选择


//延时子程序
void delay(unsigned int t)
{
  while(t--)CLRWDT();//喂狗
}

//初始化硬件子程序
void IntiPort(void)
{
  TRISIO&=~0x07;//GPIO0~GPIO3为输出
  OPTION&=~0x80;
  WPU=0b0111;//GPIO2为弱上拉,GPIO0,GPIO1输出高电平
  CMCON=0x07;//比较器关闭(功耗最低)
  ANSEL&=0xf0;//GPIO设置为数字IO
}

//主程序
void main()
{
  IntiPort();//初始化硬件子程序
  ei();//开中断
  while(1)
  {
    CLRWDT();
    delay(40000);
    NOP();
    NOP();
    GPIO0^=1;
    GPIO1^=1;
    GPIO2^=1;
    NOP();
    NOP();
    delay(40000);
  }
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2010-8-31 08:47:11 | 显示全部楼层
没有人指点下吗?
昨晚用编程器看了下,在0x3fe 0x3ff地址处的数据是0xff 0x3f,我把他们更改为0x00 和0x34后,有一片能工作,但是其余三片还是不能工作,不知道是怎么回事!
请有经验的人士帮忙,指点一二,谢谢!

出0入0汤圆

发表于 2010-8-31 08:59:13 | 显示全部楼层
内部RC震荡,MCRL必须做问外部复位引脚

出0入0汤圆

发表于 2010-8-31 09:16:20 | 显示全部楼层
"#include "pic.h"

__CONFIG(0x0044);
//高门槛电压,取消MCRL,将GP3配置为数字IO,程序保护,数据区保护,看门狗停止,BOD使能,上电延时定时器启动,内部RC晶体
"

both are stupid ways of coding the chip. You should always stay with the right approach for header files, like the following:

==============
#include <htc.h>

__CONFIG(MCLRDIS & BORDIS & WDTDIS & PWRTEN & INTIO);  //add others as you wish
==============

"//延时子程序
void delay(unsigned int t)"

the parameter to delay is an unsigned int. so make sure that when you call this routine, it doesn't exceed the maximum value of unsigned int.

" TRISIO&=~0x07;//GPIO0~GPIO3为输出 "

really? you must have not read the datasheet.

" OPTION&=~0x80;"

why do you need this?


"  WPU=0b0111;//GPIO2为弱上拉,GPIO0,GPIO1输出高电平"

you are enabling wpu on an output pin? have you lost your mind?

"  CMCON=0x07;//比较器关闭(功耗最低)"

good.

"  ANSEL&=0xf0;//GPIO设置为数字IO"

doesn't make sense.

"  ei();//开中断"

why?

"    CLRWDT();"

totally moronic.

"    NOP();
    NOP();"

totally moronic.

"    NOP();
    NOP();
    delay(40000);"

totally moronic.

you need to understand what you are doing. to do that, you need to read the datasheet, many times over.

right now, you have no clue what you are trying to do.

出0入0汤圆

 楼主| 发表于 2010-8-31 13:38:10 | 显示全部楼层
楼上的牛人!!
" TRISIO&=~0x07;//GPIO0~GPIO3为输出 "

really? you must have not read the datasheet.
难道不是吗??
bit 7-6: 未用位:读作0
bit 5-0: TRISIO<5:0>:通用 I/O三态控制位
1 = GPIO引脚被配置为输入引脚(三态)
0 = GPIO引脚被配置为输出引脚。
注: TRISIO<3>始终读做1。

出0入0汤圆

 楼主| 发表于 2010-8-31 13:39:58 | 显示全部楼层
这个程序是我实在不行的时候用来测试的!
因为下载下去都不可以运行
不过昨晚最后弄的时候,有一片能运行了。
现在不知道是什么原因引起的

出0入0汤圆

发表于 2010-8-31 18:38:19 | 显示全部楼层
"现在不知道是什么原因引起的"

because the coding is terrible?

try something like this:

==========code============

#include <htc.h>

__CONFIG(MCLRDIS & WDTDIS & BORDIS & PWRTEN & INTIO);

#define IO_SET(port, bits)        port |= (bits)                //set bits on port
#define IO_CLR(port, bits)        port &=~(bits)                //clear bits on port
#define IO_FLP(port, bits)        port ^= (bits)                //flip bits on port

#define IO_IN(ddr, pins)        ddr |= (pins)                //pins as input
#define IO_OUT(ddr, pins)        ddr &=~(pins)                //pins as output

#define OUT_PORT                GPIO
#define OUT_DDR                        TRISIO
#define OUT0                        (1<<4)                //digital out on gpio4
#define OUT1                        (1<<1)                //digita out on gpio1

#define AN_PORT                        GPIO
#define AN_DDR                        TRISIO
#define AN                                (1<<0)                //analog in on gpio0

#define DLY                                30000                //delay cycles

void delay(unsigned int dly) {                //delay
        while (dly--) NOP();
}

void mcu_init(void) {                                //initiate the mcu
        ANSEL=0x00;                                                //all pins digital
        CMCON=0x07;                                                //analog comparators off

        ANSEL |= AN;                                        //AN to be analog in
        //IO_IN(AN_PORT, AN);                                //an to be digital in
        IO_CLR(OUT_PORT, OUT0 | OUT1);        //out0/1 cleared
        IO_OUT(OUT_DDR, OUT0 | OUT1);        //out0/1 to be digital output
}

void
main(void)
{
        mcu_init();
        while (1){
                //TODO Auto-generated main function
                IO_FLP(OUT_PORT, OUT0 | OUT1);        //flip out0/1
                delay(DLY);                                        //delay some time
        }
}
================================

I didn't set up the analog part of it completely but the code will flip output on OUT0 and OUT1.

出0入0汤圆

发表于 2010-8-31 18:39:39 | 显示全部楼层
"不知道是什么原因引起的!!
...
软件仿真都可以的,"

that may suggest problems with your programmer.

出0入0汤圆

 楼主| 发表于 2010-9-1 12:51:54 | 显示全部楼层
多谢楼上的热心帮助,我想问题已经解决了,因为我用编程器看flash里面的数据,0x3ff的数据如果是0xff 0x3f是肯定不能运行的,如果我用另外一个编程器将这些位置更改为0x00 0x34,则可以正常运行。
估计这个位置的值是有关系的。
然后还发现了一个问题,就是有些单片机第一次看flash就已经是错误的,不知道原因是什么,不过只要能将这个位置的值修改,就肯定可以运行。
不过在实际操作中发现,有几片是不能修改的,不明白是什么道理。

出0入0汤圆

发表于 2010-9-1 13:24:53 | 显示全部楼层
flash里最后位置数据是RC震荡器有关的,改的太过了就不起振了。一般读出来都是在0x3440到0x3460

出0入0汤圆

发表于 2010-9-2 07:15:01 | 显示全部楼层
at 0x3ff is your OSCCAL. you are NOT supposed to change that.

出0入0汤圆

 楼主| 发表于 2010-9-3 23:15:30 | 显示全部楼层
I don't want to change it, maybe it change itself.
Because my programmer will protect this byte.
Whatever value I change in the hex file of this byte,it will not change when finished program it.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-30 11:01

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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