最新MC96F8208现代芯片C语言程序Word文档下载推荐.docx
- 文档编号:22671169
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:51
- 大小:23.39KB
最新MC96F8208现代芯片C语言程序Word文档下载推荐.docx
《最新MC96F8208现代芯片C语言程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《最新MC96F8208现代芯片C语言程序Word文档下载推荐.docx(51页珍藏版)》请在冰豆网上搜索。
--AD3input
RXD/LEDe<
6|P31/RXD/(SCL)AN8/BUZO/EINT11/P11|15<
--COM1
TXD/LEDd<
7|P30/TXD/(SDA)AN9/PWM1/EINT11/P12|14<
--COM2
LEDc<
8|P25/SCLAN10/PWM2/EINT12/P13|13-->
PWM2
LEDb<
9|P24/SDAAN11/MISO/P14|12<
--COM3
LEDa<
10|P16/AN13/SCKAN12/MOSI/P15|11<
--COM4
-------------------------------------------
*/
//------------------------------------------------------------------------------
//Includefileandvariable
#include<
MC96F8208S.h>
intrins.h>
Typedef.h>
#definefocus0
#include"
Variable.h"
Main.h"
//initialpart
voidDelay1ms(unsignedcharDelayCount)
{
unsignedchari,j;
for(i=0;
i<
DelayCount;
i++)
{
for(j=0;
j<
250;
j++)
{
nop;
}
}
}
voidMCUInitialSetting()
{
//SystemClockSelect&
builtinresetlevelselect
#ifCRYSTAL
P3FSR=0xC0;
//7=1:
P37_XOUT,6=1:
P36_XIN
SCCR=0x00;
//INTRCOSC(fIRC)forsystemclock
OSCCR=0x22;
//externalOSCenablestart,INT-RC/2(8MHz)
Delay1ms(100);
//16ms
SCCR=0x01;
//external4.194304MHzmainOSC(fxin)forSystemclock
OSCCR=0x06;
//internalRCOSCdisable,externalmainOSCenable
#else
OSCCR=0x20;
//internalRCOSC8MHz
#endif
LVRCR=0x00;
//builtinreset1.6Vset,LVRCR.0=0enable!
!
//b7b6b5b4b3b2b1b0
//AN3AN2DSCLDSDA
P0IO=0x03;
//----ininoutout
P0OD=0x03;
//----PPPPODOD//0Push-pulloutput,1Open-drainoutput
P0PU=0x03;
//----offoffonon
P0=0x03;
//----0011
P03DB=0x00;
//00P35DB---P03DBP02DB76=01:
fx/4=1usnoisefiltering//ConfigureDebounce---Disable
P0FSR=0x18;
//00011000
//I/Ocom4com3PWM2com2com1
P1IO=0xff;
//-outoutoutoutoutout-
P1OD=0x00;
//-PPPPPPPPPPPP-
P1PU=0x00;
//-offoffoffoffoffoff-
P1=0x36;
//-011011-
P12DB=0x00;
//----P13DBP12DBP11DB-//ConfigureDebounce---Disable
P1FSRH=0x00;
//00P160P150P140//I/OPort
P1FSRL=0x20;
//0PWM20P120P1100//I/OPort
//I/OI/O
P2IO=0x30;
//--outout----
P2OD=0x00;
//--PPPP----
P2PU=0x00;
//--oFFoFF----
P2=0x00;
//--00----
P2FSR=0x00;
//------00//P25isI/O,P24isI/O
//BUZI/OI/OI/OI/OI/O
P3IO=0xff;
//OUTOUTout--outOUTOUT
P3OD=0x00;
//PPPPPP--PPPPPP
P3PU=0x00;
//offoffoff--offoFFoFF
P3=0x00;
//000--000
//P3FSR=0xE1;
//111--001
EIPOL1=0x00;
//ExtInt8fallingedgetrigger
EIPOL0L=0x00;
//ExtInt3~0PolarityRegisterLow
EIPOL0H=0x00;
//ExtInt7~4PolarityRegisterHigh
EIFLAG0=0x00;
//ExtIntFlagRegister0
EIFLAG1=0x00;
//ExtIntFlagRegister1
IE=0x80;
//(EA)-ExG0--Ex12Ex11Ex10
IE1=0x00;
//---(TX)(RX)I2CEx6Ex5
IE2=0x0e;
//--ExG1-T2(T1)T0T0V
IE3=0x04;
//---BITWDT(WT)SPIADC
//AD寄存器初始化
ADCCRH=0x07;
//clock=fx/8,LSBsaveADCvalue,高8位AD使用低4位3:
0,低8位AD全部使用7:
ADCCRL=0x90;
//内部VDD作为参考
T1_1s=0;
T1_minute=0;
T1_hour=0;
Menu=0;
Vpoc=1;
EEPword=0;
//task:
TimerandInterruptstart
voidTimer_Start()
#ifCRYSTAL//externalOSC4.194304MHz
T0CR=0x85;
//PCS=4.194304MHz/8=524288Hz(1.9073486us),Timer0enable
T0DR=0x83;
//1.9073486usx131=249.862666us
WTCR=0x81;
//61.03515625uswatchtimer--mainosc4.194304MHz/256=16.384KHz(61.03515625us)
WTDR=0xD2;
//61.03515625usx82=5.00488msinterval
//WT中断计算公式:
Fwck=Fx/128=32768;
WT频率=Fwck/2^14=2Hz;
即每周期生产一个中断=500ms;
T1CRH=0x80;
//Timer1enable
T1ADR=259;
//15.258789usx260=3.9998msinterval
T1CRL=0x40;
//pcs=4.194304MHz/64=65.536KHz(15.258789us)
T1CRH=0x81;
//Timer1start
T2CRH=0xb0;
//Timer2enable,PWM2O是重复模式
T2ADR=259;
//15.258789usx260=3.9998msinterval频率周期为4ms
T2CRL=0x40;
T2CRH=0xb1;
//Timer2start
BITCR=0x4E;
//BIT=4.19MHz/128=32.768KHz(30.517578us)30.517578us*128=3.906ms
WDTDR=0xfa;
//3.906x250=976.5mswatchdogrefreshcycle
WDTCR=0xE0;
//WDTenableandrefresh
#else//internalRCOSC8MHz
//PCS=8MHz/8=1000000Hz(1us),Timer0enable
T0DR=0xF9;
//1usx250=250us
//32uswatchtimer--mainosc8MHz/256=31.25KHz(32us)
WTDR=0xfc;
//32*125=4ms溢出,清计数器
T1ADR=3999;
//1usx4000=4msinterval
T1CRL=0x60;
//pcs=8MHz/8=1us
//T2ADR=3999;
//1usx4000=4msinterval频率周期为4ms
T2ADR=19;
//1usx20=20usinterval频率周期为20us
T2CRL=0x60;
//Timer2start
//BIT=8MHz/128=62.5KHz(16us)16us*128=2.048ms
//2.048x250=512mswatchdogrefreshcycle
//+++++++++++++++++++++++++++++++++++++++++++
//ADC
//input:
AN
//output:
8bitADCvalue
ucharADdata(ucharAn)//带变量的函数
ucharTempData=0;
ADCCRL&
=0xf0;
//清通道选择位
nop;
ADCCRL|=An;
//选择通道
ADCCRL|=ADST;
//开启ADC转换
//等待转换完成
while(!
(ADCCRL&
0x10));
//为真,转换AD完成--此处一定要用按位&
运算符,用逻辑&
&
会出现AD通道错乱现象
TempData=ADCDRL>
>
4;
TempData|=ADCDRH<
<
=~ADST;
//STOPADC
returnTempData;
//TempData的值返回给了ADdata()函数
voidAD_AN2(void)
uchari;
for(i=0;
8;
{
rADC[0]+=ADdata(AN2);
//TempData的值返回给了ADdata()带变量的函数
}
AD2=rADC[0]/8;
//取8次平均值
rADC[0]=0;
CapacityV=0;
CapacityV=AD2/5;
//每5个AD为0.1V
voidAD_AN3(void)
rADC[1]+=ADdata(AN3);
AD3=rADC[1]/8;
rADC[1]=0;
AdAn3=0;
201;
if(AD3<
RtTable[AdAn3])AdAn3++;
//注意正温转感器与负温转感器的问题来设置数组是小于还是大于判断
elsei=202;
//不成立,提前退出,不进行空等待
if(AdAn3>
=200)AdAn3=200;
//++++++ADCProcess+++++++++++++++++++++++++++++++++++++
voidProcess_AD(void)
AD_AN3();
}
/*-------------------------------------------------------------------------*/
voidBeeperOn(void)
buzon=1;
m_State|=BZSTATE_SOUND;
//m_state控制BUZON&
BUZOFF
m_Tmr=m_OnTime;
voidBeeperOff(void)
buzon=0;
m_State&
=(~BZSTATE_SOUND);
m_Tmr=m_OffTime;
voidBeeperSet(ucharp_OnTime,ucharp_OffTime,ucharp_Repeat)
m_OnTime=p_OnTime;
m_OffTime=p_OffTime;
m_Repeat=p_Repeat;
if(p_Repeat)
{
BeeperOn();
}
else
BeeperOff();
voidBeeperControl(void)
if((Tick10ms&
TICK10MS_BEEP)==0)//1111,1111&
0000,0010=0000,0010=1
return;
Tick10ms=Tick10ms&
(~TICK10MS_BEEP);
//0000,0010&
~0000,0010=0000,0010&
1111,1101=0000,0000
if(m_Repeat==0)//蜂鸣次数,多少次
/*dutycheck*/
if(m_Tmr)//蜂鸣的开或关的时间长短
m_Tmr--;
/*toggle*/
if(m_State&
BZSTATE_SOUND)//m_state控制BUZON&
m_Repeat--;
//-----------------------------------------------------------------
//ReadKey
voidReadKey()
{//数码管注意是共阴
com4=1;
com1=1;
com2=1;
com3=1;
//关所有显示
nop;
LEDa=0;
LEDb=0;
LEDc=0;
LEDd=0;
LEDe=0;
LEDf=0;
LEDg=0;
LEDh=0;
//关所有显示
P2PU=0x30;
//Rup
P2IO=0x00;
//input
P3PU|=0x7f;
P3IO&
=0x80;
//P37OUTPUT,Otherinput
P2=0xff;
P3|=0x7f;
if(xiao_dou_time<
=2000)xiao_dou_time++;
if(KEY1==0)
{
if(xiao_dou_time==12)
{
Menu++;
Vpoc=0;
//只要有任一按键按下AN2为普通I/O对电容充电
P0FSR=0x10;
//AN2isI/O,AN3isAD
P0IO=0x07;
//AN2isoutput
P0=0x04;
//AN2为高电平对电容进行充电
DelayBUZ=1;
count_1s=0;
//每1秒钟数字加
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 MC96F8208 现代 芯片 语言 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)