中级会员
- 积分
- 305
- 威望
- 235
- 贡献
- 56
- 兑换币
- 0
- 注册时间
- 2010-10-24
- 在线时间
- 7 小时
|
程序单步好像都没法运行下去,每次在LCD_init()处都会跳入一个好像什么背景调试模式
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include<mc9s12dg128.h>
#define LCD_RS PORTB_BIT0
#define LCD_RW PORTB_BIT1
#define LCD_E PORTB_BIT2
#define LCD_DB PORTA
void LCD_init(void);//初始化函数
void LCD_write_command(uchar command);//写指令函数
void LCD_write_data(uchar dat);//写数据函数
void delay_n1ms(uint n);//延时函数
void LCD_dis(void);
void PWM_init(void);
void measure_f(void);
//*****定义全局变量*****//
int count=0;
uchar f=2;
long int f1=2000000,N;
int first=0,second=0;
//*****主函数****//
void main(void) {
DDRA=0xFF;
PORTA=0xFF;
PUCR_PUPAE=1; //设置A口为LCD的数据口
DDRB=0xFF;
PORTB=0xFF;
PUCR_PUPBE=1;
PWM_init();
PWME=0x01;
PTT_PTT0=PTP_PTP0;
DisableInterrupts;
TSCR2=0x82; //定时器中断使能位,定时器预分频系数=4;
TIOS=0xFE;
TCTL4=0x01;//扑捉上升沿
ICSYS=0x0A;
TIE=0x01;
TSCR1=0x80;
EnableInterrupts;
LCD_init(); //LCD初始化
for(;;){
LCD_dis(); //LCD显示频率
}
}
//*****PWM初始化函数*****//
void PWM_init(void){
PWME=0x00; //禁止PWM输出
PWMCTL=0x00; //通道不级联
PWMPRCLK=0x66; //
PWMCLK=0xFF; //
PWMSCLA=0x7D; //
PWMSCLB=0x7D; //
PWMPOL=0xFF; //
PWMCAE=0x00; //
PWMPER0=0x13; //
PWMDTY0=0x09; //
}
void LCD_dis(void){
LCD_write_command(0x80);
LCD_write_data(f/100+0x30);
LCD_write_data(f%100/10+0x30);
LCD_write_data(f%100%10+0x30);
LCD_write_data('H');
LCD_write_data('Z');
delay_n1ms(500);
}
//*******初始化函数*******//
void LCD_init(void) {
LCD_write_command(0x38);//设置格式,2行,5*7
delay_n1ms(1);
LCD_write_command(0x0c);
delay_n1ms(1);
LCD_write_command(0x06);//显示地址加1模式
delay_n1ms(1);
LCD_write_command(0x01);//清除屏幕显示 r54
delay_n1ms(1);
}
//******写指令函数*******
void LCD_write_command(uchar command){
delay_n1ms(1);
LCD_DB=command;
LCD_RS=0;
LCD_RW=0;
LCD_E=1;
_asm(nop);
_asm(nop);
_asm(nop);
LCD_E=0;
}
//*****写数据函数*****//
void LCD_write_data(uchar dat) {
delay_n1ms(1);
LCD_DB=dat;
LCD_RS=1;
LCD_RW=0;
LCD_E=1;
_asm(nop);
_asm(nop);
_asm(nop);
LCD_E=0;
}
//****延时函数****//
void delay_n1ms(uint n) {
uint i,j;
for(i=0;i<n;i++) {
j=0x1300;
while(j--);
}
}
//void measure_f(void)
#pragma CODE_SEG_NEAR_SEG NON_BANKED
interrupt void CH0IC(void){
first=TC0H;
second=TC0;
N=count*65536+second-first;
f=f1/N;
TFLG1=0x01;
count=0;
}
interrupt void TOI(void) {
count++;
TFLG2_TOF=1;
}
#pragma CODE_SEG DEFAULT |
|