找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

各位大神们~遇到51单片机的问题~求赐教求给力~

[复制链接]
admin 发表于 2012-9-2 10:04:57 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4
这是程序,用的是89C52芯片,功能是实现对晶振频率的测量,并显示在液晶屏上面。先通过计数器393计数,进位后输入到T0口进行计数,T1口做定时 器,最后分别测出10ms的脉冲值和60ms的脉冲值,(60ms-10ms)*20即为1s的脉冲值,得到频率。这是学长给我的程序,基本弄懂,但是 start_count和CLR_COUNT究竟是什么参数,起什么作用(我已用问号标注),运行是会出现这样的错误:
COUNTERCTRL.H(6): error C202: 'START_COUNT': undefined identifier
COUNTERCTRL.H(7): error C202: 'CLR_COUNT': undefined identifier
COUNTERCTRL.H(12): error C202: 'CLR_COUNT': undefined identifier
COUNTERCTRL.H(13): error C202: 'START_COUNT': undefined identifier
COUNTERCTRL.H(18): error C202: 'START_COUNT': undefined identifier
是不是定义个bit 就可以了?但是我想知道这些参数在这里的意义啊,求赐教。

主程序
?
#include <reg52.h>
#include <stdio.h>
#include "Timer.h"
#include "SMC1602C.h"
#include "CounterCtrl.h"
?
?
main()
{
?????? unsigned long ulVal10ms = 0;
?????? unsigned long ulVal60ms = 0;
?????? unsigned long ulF?????????= 0;
?????? char szF[32];
??????
?????? lcdreset();
?????? InitTimer1();
?????? while (1)
?????? {
?????????????ulVal10ms = Delay10ms();
?????????????ulVal60ms = Delay60ms();
?????????????ulF = (ulVal60ms - ulVal10ms) * 20;
?????????????sprintf(szF, "%lu Hz", ulF);
?????????????lcdwda(0, 0, szF);
?????? }
}
?
2 时间控制子程序
#include <reg52.h>
#include "Timer.h"??
#include "CounterCtrl.h"
?
static bit bTimerOverflow;
?
static unsigned long GetCounterVal(void)
{
?????? unsigned longulLowByte;?????
?????? unsigned long ulHiByte;
?????? unsigned long ulHiWord;
??????
?????? ulLowByte = COUNT_VAL;???//计数器393输出低八位
?????? ulHiByte =TL0;?????????????//TL0输出中间八位
?????? ulHiWord =TH0;?????????? //THO输出高八位;T0做计数器用
??????
?????? return ((ulHiWord << 16)
?????????????+ (ulHiByte << 8)
?????????????+ ulLowByte);???????? //返回最后的计数值
}
?
voidInitTimer1(void)???????????//初始化计数器和定时器
{
??????EA???????? = 1;???//enable interrupt
??????ET1??????? = 1;??? //enableinterrupt of timer 1
?????? TMOD??? = 0x15;??//timer 1 mode 3, counter 0 mode 3? TO计数器 T1 定时器
}
?
unsigned long Delay10ms(void)
{
?????? TL1 = 0x00;????
?????? TH1 = 0xDC;
?????? TL0 = 0x00;
?????? TH0 = 0x00;
??????
?????? Reset_Count();
?????? bTimerOverflow = 0;
?????? TR0 = 1;???? //T0工作
?????? TR1 =1;??????? //start timer 1
?????? Start_Count();
?????? while (!bTimerOverflow);
?????? return GetCounterVal();
}
?
unsigned long Delay60ms(void)
{
?????? TL1 = 0x00;
?????? TH1 = 0x28;
?????? TL0 = 0x00;
?????? TH0 = 0x00;
??????
?????? Reset_Count();
?????? bTimerOverflow = 0;
?????? TR0 = 1;
?????? TR1 =1;??????? //start timer 1
?????? Start_Count();
?????? while (!bTimerOverflow);
?????? return GetCounterVal();
}
?
static void timer1(void) interrupt 3 using 0
{
?????? Stop_Count();
?????? TR0 = 0;
?????? TR1 =0;??????? //stop timer 1
?????? bTimerOverflow = 1;
}
?
?
3 测量子程序
?
#include "CounterCtrl.h"?
?
?
void Reset_Count(void)
{
????? START_COUNT = 0;//这几个参数哪来的什么作用??????
????? CLR_COUNT???? = 1;
}
?
void Start_Count(void)
{
????? CLR_COUNT???? = 0;
????? START_COUNT = 1;
}
?
void Stop_Count(void)
{
????? START_COUNT = 0;
}

?
4 液晶显示子程序
?
#include<reg51.h>
#include<intrins.h>
#include "SMC1602C.h"
?
sbit RSPIN???? = P3^7;
sbit RWPIN??? = P3^6;
sbit EPIN?????? = P3^5;
?
static unsigned char XPOS,YPOS;
?
static void delay(unsigned int t)
{
?????? unsigned int i,j;
?
?????? for(i = 0; i < t; i++)
?????????????for(j = 0; j < 10; j++);
}
?
static void lcdwaitidle(void)
{
??????P1????????? = 0xff;
?????? RSPIN??? = 0;
?????? RWPIN?? = 1;
?????? EPIN????? = 1;
?????? while((P1 & 0x80) == 0x80);
?????? EPIN????? = 0;
}
?
static void lcdwcn(unsigned char c)
{
?????? RSPIN??? = 0;
?????? RWPIN?? = 0;
??????P1????????? = c;
?????? EPIN????? = 1;
?????? _nop_();
?????? EPIN????? = 0;
}
?
static void lcdwc(unsigned char c)
{
?????? lcdwaitidle();
?????? lcdwcn(c);
}
?
static void lcdwd(unsigned char d)
{
?????? lcdwaitidle();
?????? RSPIN??? = 1;
?????? RWPIN?? = 0;
??????P1????????? = d;
?????? EPIN????? = 1;
?????? _nop_();
?????? EPIN????? = 0;
}
?
static void lcdpos(void)
{
?????? XPOS &= 0x0f;
?????? YPOS &= 0x03;
?????? if(YPOS == 0x00)
?????????????lcdwc(XPOS | 0x80);
?????? else if(YPOS == 0x01)
?????????????lcdwc((XPOS + 0x40)|0x80);
?????? else if(YPOS == 0x02)
?????????????lcdwc((XPOS + 0x10)|0x80);
?????? else
?????????????lcdwc((XPOS + 0x50)|0x80);
}
?
void lcdreset()
{
?????? delay(150);
?????? lcdwcn(0x38);
?????? delay(50);
?????? lcdwcn(0x38);
?????? delay(50);
?????? lcdwcn(0x38);
?????? lcdwc(0x38);
?????? lcdwc(0x08);
?????? lcdwc(0x01);
?????? lcdwc(0x06);
?????? lcdwc(0x0c);
}
?
void lcdfill(unsigned char n)
{
?????? for(YPOS = 0; YPOS < 2; YPOS++)
?????????????for(XPOS = 0; XPOS < 16; XPOS++)
?????????????{
????????????????????lcdpos();
????????????????????lcdwd(n);
?????????????}
}
?
void lcdwda(unsigned char x, unsigned char y, unsigned char *s)
{
?????? YPOS = y;
?????? for(XPOS = x; XPOS < 16; XPOS++)
?????? {
?????????????lcdpos();
??? ?????? lcdwd((*s == '\0') ? '': *s++);
??? ?????? delay(100);
?????? }
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-28 08:26 , Processed in 0.057590 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表