小弟新使用NEC单片机(uPD78F1213) 写个程序运行不了 求高人指点
最近使用NEC 78K0R/IC3 系列的1213写程序练手 做了个板子直接往里烧程序。仿造官网上1166的例程写了一个TM02计数 输出4s半周的方波的程序。烧进去测TO02没有反应,求指点。#include "K0R_def.H" //此处中文注释为后加 ,此头文件定义了一些头文件和sfr di等等
void Wave_init(void)
{
/******** CPUsetting ******/
PER0 = 0b10100100; /* RTCEN=ADCENSAU0EN=1: supplies input clock to RTC, ADC, SAU */
PER1 = 0b00001000; /* OACMPEN=1: comparator/programmable gain amplifier*/
PER2 = 0b00000011; /*TAUOPEN=TAU0EN=1:inverter control function and TAUS*/
/******** clock setting
using internal 8MHz as the main clock ******/
CMC = 0b00000000;
/*****************************************
X1 clock oscillation stabilization wait time when STOP mode is released */
OSTS = 0x07; /* OSTS2=OSTS1=OSTS0=1: 2^18/fx */
CSC = 0b00000000; /* MSTOP=0: X1 operating
XTSTOP=0: XT1 operating
HIOSTOP=0: internal high-speed oscillator operating */
while(OSTC != 0xff); /* oscillation stabilization ? */
CKC = 0b00001001; /* CLS=0: fCLK = main system clock (fMAIN)
MCS=0: fMAIN = internal high-speed oscillation clock (fIH) 8MHz(TYP)
CSS=MCM0=MDIV2=MDIV1=0 MDIV0=1: fCLK = fIH/2=4MHz(TYP) */
DSCCTL = 0b00000000; /*Do not use 40 MHz Internal High-speed Oscillation*/
/********TAUS setting*******/
TPS0 = 0x0008; /* timer clock (CK00) = fCLK/(2^8)64 us */
TMR02 = 0x0000; /* CKS02=0: operation clock CK0 set by PRS register */
/* CCS12=CCS02=0: operation clock MCK specified by CKS02 bit */
/* MASTER02=0: independent channel mode */
/* STS022-0=0: only software trigger start is valid */
/* MD023-0=0: interval timer mode, no timer interrupt when counting starts */
TDR02 = 62500-1; /* interval period = 4s(64us * 62500) */
TOM0 = 0b0000000000000000; /* TOM00-11=0: timer output (TO0-11) mode: toggle mode */
TOL0 = 0b0000000000000000; /* TOL00-11=0: timer output (TO0-11) level: postive logic output (active-high) */
TO0 = 0b0000000000000000; /* TO00-11=0: timer output (TO0-11) value: "0" */
TOE0 = 0x0004; /* Enables the TO02 output operation by counting operation */
/* (Enables to Square wave output) */
PM1.0 = 0; /* output */
P1.0 = 0; /* P10(TO02) */
}
void Wave_start(void)
{
TOE0 = 0x0004;
TS0 = 0x0004;
TMIF02 = 0; /* clear interrupt request flag (INTTM02) */
TMMK02 = 0; /* clear interrupt mask flag (INTTM02) */
}
void Wave_stop()
{
TT0 = 0x0004; /* Operation is stopped of Channel2 */
TOE0 = 0x0000; /* timer output (TO2) operation stopped by count operation */
}
void main(void)
{
Wave_init(); /* Initial Setting */
Wave_start(); /* Operation Start */
/* main loop */
while(1){
WDTE = 0xac; /* watchdog timer counter clears and restarts */
NOP();
if(TMIF02 == 1){
TMIF02 = 0;
NOP();
NOP();
NOP(); }
}
Wave_stop();
}
以上为程序,求人指点。
吐槽:PM+真不好用,官网例程也就改改寄存器,还每个程序都用个不知所云的init.c ,英文datasheet看的头大 大哥,你那有1213的中文资料吗?给我小弟来一份。 用applilet自动生成代码啊,直接选项式配置寄存器,保证正确。然后再添加自己的逻辑控制代码。
还有我以前的经验是绝对不要用中文注释。 回复【楼主位】zhengxl07
-----------------------------------------------------------------------
没使能总中断吧。我一开始就用IAR,官方都承认不如IAR。 回复【3楼】linminsong
-----------------------------------------------------------------------
如果PM+比专门做编译器的IAR好的话,IAR卖给谁啊? 点击此处下载 ourdev_665335UAMSJH.pdf(文件大小:6.70M) (原文件名:78f1213.pdf)
78f1213的中文资料来了
页:
[1]