2024年3月25日发(作者:)

240128的程序

#include

#include

#include

//

//

sfr16 DP = 0x82; // data pointer

sfr16 TMR3RL = 0x92; // Timer3 reload value

sfr16 TMR3 = 0x94; // Timer3 counter

sfr16 ADC0 = 0xbe; // ADC0 data

sfr16 ADC0GT = 0xc4; // ADC0 greater than window

sfr16 ADC0LT = 0xc6; // ADC0 less than window

sfr16 RCAP2 = 0xca; // Timer2 capture/reload

sfr16 T2 = 0xcc; // Timer2

sfr16 RCAP4 = 0xe4; // Timer4 capture/reload

sfr16 T4 = 0xf4; // Timer4

sfr16 DAC0 = 0xd2; // DAC0 data

sfr16 DAC1 = 0xd5; // DAC1 data

//

unsigned int ad_temp,dis_y=0;

unsigned char ad_i=0;

char tabc;

unsigned char dis_i,dis_k=0;

//

unsigned char t_count,t_i;

unsigned int t_timecount;

bit t_flag;

unsigned long t_y=0;

//

void SYSCLK_Init (void)

{

unsigned int i; // delay counter

OSCXCN = 0x67; // start external oscillator with

for (i=0; i < 3000; i++) ; // Wait for osc. to start up

while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle

OSCICN = 0x88;

}

//-----------------------------------------------------------------------------

//函数名称: PORT_Init ()

//函数功能: 通用I/O口及交叉开关初始化

//入口参数: 无

//出口参数: 无

//全局变量引用: 无

//调用模块: 无

//-----------------------------------------------------------------------------

void PORT_Init (void)

{

XBR1 = 0x02;

XBR2 = 0x40;

P74OUT = 0x0f; // P2口设为推挽方式

P4=0x07;

}

//

void T_Init(void)

{

CKCON=0X18;

TMOD=0x15;

IP=0x0a;

TH0=0;

TL0=0;

TH1=(65536-44237)/256;

TL1=(65536-44237)%256;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

}

// ADC0配置,T3定时启动ADC

//-----------------------------------------------------------------------------

void ADC0_Init (void)

{

ADC0CN = 0x00; // ADC0 向AD0BUSY写1时采样,左对齐

REF0CN = 0x03; // 启用内部基准源

ADC0CF =0X40;

AMX0SL = 0x01;

AD0EN =1; // 选择采样输入源

EIE2 |= 0x02; // 启用 ADC 中断

}

//

void t0(void) interrupt 1

{

t_count++;

}