在使用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);
}
}
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.
一周热门 更多>