山东大学单片机实验

  • 格式:doc
  • 大小:516.50 KB
  • 文档页数:9

信息科学与工程学院

2016-2017学年第二学期

实 验 报 告

课程名称: 单片机原理与应用

实验名称: 3.8 ADC0808/9信号采集实验

实验报告

【实验题目】

本实验利用LCD1602和AD0808实现简单的交流信号过零检测与频率分析。要求信号幅度变化时(满量程的5%~95%),不影响检测的结果。频率检测的结果通过LCD1602的第1行显示出来,信号过零时,能够通过P2.6输出一个脉冲宽度为5微秒的脉冲信号。

【实验要求】

1.编写源程序并进行必要的注释;

2.记录实验过程;

3.记录程序运行结果;

【实验过程及结果记录】

自我完成实验

A.电路图

B.运行结果

频率监测

过零检测

【实验源程序】

#include

#include

#define uint unsigned int

#define uchar unsigned char

sbit LCD_RS=P2^0;

sbit LCD_RW=P2^1;

sbit LCD_EN=P2^2;

sbit AD_CLK=P2^3;

sbit Start=P2^4;

sbit OE=P2^5;

sbit Out_pulse=P2^6;

sbit EOC=P2^7;

uchar tx50=0;

uchar f=0;

uchar date,lastdate,ge,shi;

void delay_ms(uint xms)

{

uint i,j;

for(i=xms;i>0;i--)

{

for(j=110;j>0;j--);

}

}

bit lcd_busy()

{

bit result;

LCD_RS=0;

LCD_RW=1;

LCD_EN=1;

_nop_();

_nop_();

_nop_();

_nop_();

result=(bit)(P1&0x80);

LCD_EN=0;

return result;

}

void lcd_wcmd(uchar cmd)

{

while(lcd_busy());

LCD_RS=0;

LCD_RW=0;

LCD_EN=0;

_nop_();

_nop_();

P1=cmd;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EN=1;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EN=0;

}

void lcd_clr()

{

lcd_wcmd(0x01);

delay_ms(2);

}

void lcd_wdat(uchar dat)

{

while(lcd_busy());

LCD_RS=1;

LCD_RW=0;

LCD_EN=0;

_nop_();

_nop_();

P1=dat;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EN=1;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EN=0;

}

void lcd_init()//初始化子程序

{

delay_ms(15);

lcd_wcmd(0x38);//8位数据总线,显示2行,5*7点阵

delay_ms(5);

lcd_wcmd(0x0c);//显示开,关光标,不闪烁

delay_ms(5);

lcd_wcmd(0x06);//进入模式设置指令中,地址自动增加

delay_ms(5);

lcd_wcmd(0x01);//清楚LCD显示内容

delay_ms(5);

}

void s_timer0() interrupt 1

{

TH0=0x3c;

TL0=0xb0;

tx50=tx50+1;

if(tx50==20)

{

TR0=0;

tx50=0;

f=f/2;

shi=f/10;

shi=shi+'0';

ge=f%10;

ge=ge+'0';

lcd_wcmd(0x80);

lcd_wdat('F');

delay_ms(5);

lcd_wdat('=');

delay_ms(5);

lcd_wdat(shi);

delay_ms(5);

lcd_wdat(ge);

delay_ms(5);

lcd_wdat('H');

delay_ms(5);

lcd_wdat('z');

f=0;

TR0=1;

}

}

void s_timer1() interrupt 3

{

AD_CLK=~AD_CLK;

}

void main()

{

delay_ms(10);

lcd_init();

lcd_clr();

delay_ms(2);

TMOD=0x21;

TH1=0xfd;

TL1=0xfd;

TH0=0x3c;

TL0=0xb0;

EA=1;

ET0=1;

ET1=1;

TR0=1;

TR1=1;

while(1)

{

Start=1;

Start=0;

while(EOC!=1);

OE=1;

P0=0xff;

lastdate=date;

date=P0;

OE=0;

if(((lastdate<128)&&(date>=128))||((lastdate>=128)&&(date<128)))

{

f++;

Out_pulse=1;

_nop_();

_nop_();

_nop_();

_nop_();

Out_pulse=0;

}

}

}

(注:文档可能无法思考全面,请浏览后下载,供参考。可复制、编制,期待你的好评与关注!)