基于8051F350的AD转换显示存储程序文件Word文件下载.docx

上传人:b****3 文档编号:7072980 上传时间:2023-05-07 格式:DOCX 页数:34 大小:23.78KB
下载 相关 举报
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第1页
第1页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第2页
第2页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第3页
第3页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第4页
第4页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第5页
第5页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第6页
第6页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第7页
第7页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第8页
第8页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第9页
第9页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第10页
第10页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第11页
第11页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第12页
第12页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第13页
第13页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第14页
第14页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第15页
第15页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第16页
第16页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第17页
第17页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第18页
第18页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第19页
第19页 / 共34页
基于8051F350的AD转换显示存储程序文件Word文件下载.docx_第20页
第20页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

基于8051F350的AD转换显示存储程序文件Word文件下载.docx

《基于8051F350的AD转换显示存储程序文件Word文件下载.docx》由会员分享,可在线阅读,更多相关《基于8051F350的AD转换显示存储程序文件Word文件下载.docx(34页珍藏版)》请在冰点文库上搜索。

基于8051F350的AD转换显示存储程序文件Word文件下载.docx

{

K1OK=1;

3、voidT2_ISR(void)interrupt5

//定时器,定时扫描按键,当有按键按下时,显示ADZ

TF2H=0;

KeyScan();

if(K1OK==1)

K1OK=0;

//LCD1602第一行显示字母“ADZ”,第二行显示数字ADZ,24C02存储此值

 

*/

/*****

1602高四位

DB4=P1^0,

AD转换,24位精度:

AIN0.0,Verf+接100K可调电阻测试,满量程2500mv

四个按键:

存储(24C02):

SDA=P0^0,SCL=P0^1(和T2扫描按键有冲突,应该实时存储)

*****/

/////////////Routines

sfr16ADC0DEC=0x9A;

//ADC0DecimationRatioRegister

sfr16TMR3RL=0x92;

//Timer3reloadregisters

sfr16TMR3=0x94;

//Timer3counterregisters

sfr16TMR2RL=0xCA;

//Timer2ReloadRegister

sfr16TMR2=0xCC;

//Timer2Register

sbitSDA=P0^0;

//SMBusonP0.0

sbitSCL=P0^1;

//andP0.1

sbitK1=P1^4;

//四个按键

sbitK2=P1^5;

sbitK3=P1^6;

sbitK4=P1^7;

//GlobalCONSTANTS

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

#defineSYSCLK24500000//SYSCLKfrequencyinHz

#defineMDCLK2457600//ModulatorclockinHz(idealis

//(2.4576MHz)

#defineOWR20//DesiredOutputWordRateinHzADC0输出字速率,最大960

#defineBAUDRATE115200//BaudrateofUARTinbps

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

#defineSMB_FREQUENCY50000//TargetSCLclockrate

//Thisexamplesupportsbetween10kHz

//and100kHz

#defineWRITE0x00//SMBusWRITEcommand

#defineREAD0x01//SMBusREADcommand

#defineEEPROM_ADDR0xA0//Deviceaddressforslavetarget

//Note:

Thisaddressisspecified

//intheMicrochip24LC02B

//datasheet.

//SMBusBufferSize

#defineSMB_BUFF_SIZE0x08//Definesthemaximumnumberofbytes

//thatcanbesentorreceivedina

//singletransfer

//Statusvector-top4bitsonly

#defineSMB_MTSTA0xE0//(MT)starttransmitted

#defineSMB_MTDB0xC0//(MT)databytetransmitted

#defineSMB_MRDB0x80//(MR)databytereceived

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

//----------------------------------------------------------------定时器2常量

#defineTOGGLE_RATE1000//每50ms检测按键1次

#defineTIMER_TICKS_PER_MSSYSCLK/8/1000//定时器每ms触发扫描次

#defineAUX1TIMER_TICKS_PER_MS*TOGGLE_RATE

#defineAUX2-AUX1

#defineTIMER2_RELOADAUX2//ReloadvalueforTimer2

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

#defineucharunsignedchar

#defineuintunsignedint

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

sbitlcdrs=P0^6;

//数据/命令选择端,低电平为指令,高电平为数?

sbitlcden=P0^7;

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

ucharD1,D2,D3,D4,D5,D6,D7,D8;

uchar*pSMB_DATA_IN;

//GlobalpointerforSMBusdata

//Allreceivedataiswrittenhere

ucharSMB_SINGLEBYTE_OUT;

//Globalholderforsinglebytewrites.

uchar*pSMB_DATA_OUT;

//GlobalpointerforSMBusdata.

//Alltransmitdataisreadfromhere

ucharSMB_DATA_LEN;

//Globalholderfornumberofbytes

//tosendorreceiveinthecurrent

//SMBustransfer.

ucharWORD_ADDR;

//GlobalholderfortheEEPROMword

//addressthatwillbeaccessedin

//thenexttransfer

ucharTARGET;

//TargetSMBusslaveaddress

bitSMB_BUSY=0;

//Softwareflagtoindicatewhenthe

//EEPROM_ByteRead()or

//EEPROM_ByteWrite()

//functionshaveclaimedtheSMBus

bitSMB_RW;

//Softwareflagtoindicatethe

//directionofthecurrenttransfer

bitSMB_SENDWORDADDR;

//Whenset,thisflagcausestheISR

//tosendthe8-bit<

WORD_ADDR>

//aftersendingtheslaveaddress.

bitSMB_RANDOMREAD;

//tosendaSTARTsignalaftersending

//thewordaddress.

//Forthe24LC02BEEPROM,arandomread

//(areadfromaparticularaddressin

//memory)startsasawritethen

//changestoareadaftertherepeated

//startissent.TheISRhandlesthis

//switchoverifthe<

SMB_RANDOMREAD>

//bitisset.

bitSMB_ACKPOLL;

//tosendarepeatedSTARTuntilthe

//slavehasacknowledgeditsaddress

staticucharK1OK,K2OK,K3OK,K4OK;

staticucharge,shi,bai,qian;

staticunsignedlongADC_OutputVal;

//得到的份数

staticunsignedlongaccumulator=0;

//ADC累积测量N次值的和

staticuintmeasurements=0;

//ADC测量的次数

staticunsignedlongresult=0;

uinti,k;

ucharnum;

ucharcodetable1[]="

ADZ:

"

;

ucharcodetable2[]="

testdata."

//FunctionPROTOTYPES

voidOscillator_Init(void);

voidPort_Init(void);

voidUART0_Init(void);

voidADC0_Init(void);

voiddelay(uintx);

voidLcd_1602_init();

voidLcd_1602_write(ucharcom,date);

voidLcd_1602_write1();

voidSMBus_Init(void);

voidTimer0_Init(void);

voidTimer3_Init(void);

voidSMBus_ISR(void);

voidTimer2_Init(void);

voidKeyScan();

voidTimer3_ISR(void);

voidEEPROM_ByteWrite(unsignedcharaddr,unsignedchardat);

voidEEPROM_WriteArray(unsignedchardest_addr,unsignedchar*src_addr,

unsignedcharlen);

unsignedcharEEPROM_ByteRead(unsignedcharaddr);

voidEEPROM_ReadArray(unsignedchar*dest_addr,unsignedcharsrc_addr,

//MAINRoutine

voidmain(void)

charin_buff[11]={0};

PCA0MD&

=~0x40;

//WDTE=0(clearwatchdogtimer

//enable)

Oscillator_Init();

//Initializesystemclock

while(!

SDA)

//Provideclockpulsestoallowtheslavetoadvanceout

//ofitscurrentstate.ThiswillallowittoreleaseSDA.

XBR1=0x40;

//EnableCrossbar

SCL=0;

//Drivetheclocklow

for(i=0;

i<

255;

i++);

//Holdtheclocklow

SCL=1;

//Releasetheclock

SCL);

//Waitforopen-drain

//clockoutputtorise

10;

//Holdtheclockhigh

XBR1=0x00;

//DisableCrossbar

}

Port_Init();

//InitializeCrossbarandGPIO

//UART0_Init();

//InitializeUART0forprintf'

s

Lcd_1602_init();

ADC0_Init();

//InitializeADC0

AD0INT=0;

ADC0MD=0x83;

//Startcontinuousconversions

Timer0_Init();

//ConfigureTimer0foruseasSMBus

Timer2_Init();

//clocksource

Timer3_Init();

//ConfigureTimer3forusewithSMBus

//lowtimeoutdetect

SMBus_Init();

//ConfigureandenableSMBus

EIE1|=0x01;

//EnabletheSMBusinterrupt

EA=1;

//Enableglobalinterrupts

//加入按键测试-------------------

EEPROM_WriteArray(0x50,table2,sizeof(table2));

EEPROM_ReadArray(in_buff,0x50,sizeof(in_buff));

while(K1==0)

voidLcd_1602_init();

delay(3);

for(i=0;

i<

sizeof(in_buff);

i++)

Lcd_1602_write(1,in_buff[i]);

delay(3);

}

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

*/

while

(1){//Spinforever

//InitializationSubroutines

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

//1602程序部分

voidLcd_1602_init()

{

Lcd_1602_write(0,0x28);

//0x28=00101000,将液晶设置为16*2显示,5*7点阵,4位数据口

delay(5);

//

lcden=1;

lcden=0;

//显示方式设置

Lcd_1602_write(0,0x0e);

//设置开显示,不显示光标

Lcd_1602_write(0,0x06);

//默认(0x06)写入新数据后光标右移屏幕不移动

Lcd_1602_write(0,0x01);

//显示清0,数据指针清0

voidLcd_1602_write(ucharcom,date)

uchari;

uchartemp;

lcdrs=com;

//将形参传给lcdrs

2;

i++)//每次写四位,写完一个数据/命令(8位)需要两次

temp=date;

P1=(P1&

0xF0)|((temp&

0xF0)>

>

4);

//将date的高四位送入P1第四位,同时保持P1的高四位不变

//如果使用P1的低四位的话,则该处应该改为:

P1=(P1&

0xf0)|((date>

4)&

0x0f);

//适当延时,数据稳定

//送入数据

date<

<

=4;

//低四位左移到高四位

voidLcd_1602_write1(ucharcom,date)

voiddelay(uintx)//延时x毫秒

uinti,j;

for(i=x;

i>

0;

i--)

for(j=110;

j>

j--);

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

voidOscillator_Init(void)

OSCICN=0x83;

//配置内部振荡器,不分频

RSTSRC=0x04;

//Enablemissingclockdetector

//Port_Init

//

//ReturnValue:

None

//Parameters:

//ThisfunctioninitializestheGPIOandtheCrossbar初始化GPI0和交叉开关

//Pinout:

//P0.4-UARTTX(digital,push-pull)

//P0.5-UARTRX(digital,open-drain)

//AIN0.2-ADC0input

voidPort_Init(void)

//弱上拉使能,交叉开关使

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2