0804_serial port
其实这个程序总的来说是有问题的
仿真图:
MacroAndConst.h
#ifndef _MACRO_AND_CONST_H_
#define _MACRO_AND_CONST_H_
typedef unsigned int uint16;
typedef unsigned int UINT;
typedef unsigned int uint;
typedef unsigned int UINT16;
typedef unsigned int WORD;
typedef unsigned int word;
typedef int int16;
typedef int INT16;
typedef unsigned long uint32;
typedef unsigned long UINT32;
typedef unsigned long DWORD;
typedef unsigned long dword;
typedef long int32;
typedef long INT32;
typedef signed char int8;
typedef signed char INT8;
typedef unsigned char byte;
typedef unsigned char BYTE;
typedef unsigned char uchar;
typedef unsigned char UINT8;
typedef unsigned char uint8;
typedef unsigned char BOOL;
#endif
led.h
#ifndef _LED_H_
#define _LED_H_
//typedef P0 Seg;
//typedef P2 Bit;
extern void display(uint db);
#endif
led.c
#include <reg52.h>
#include "MacroAndConst.h"
//#include "delay.h"
#include "time.h"
/*---------共阴极0~f数码管编码 ----------*/
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/*****typedef int int16; 有符号的******/
static int16 LedTimeCount1=0; //LED计数器
static int16 LedTimeCount2=0;
static int16 LedTimeCount3=0;
static int16 LedTimeCount4=0;
void display(uint db) //数码管显示函数,用于显示模数转换后得到的数字量
{
uchar bw,sw,gw; //bw,sw,gw分别等于db百位,十位,个位上的数
db=db*100/51;
bw=db/100;
sw=db%100/10;
gw=db%10;
P2=0xfe; //点亮第一只数码管
P0=table[bw]|0x80; //最高位置0,点亮第一只数码管的小数点.
if(Time500us)
{
/*
Time500us=0;
LedTimeCount1++;
LedTimeCount2++;
LedTimeCount3++;
LedTimeCount4++;
if(LedTimeCount1>=4)
{
LedTimeCount1=-16;//LED计数器复位
//delay(5);
P2=0xfd; //点亮第二只数码管
P0=table[sw];
}
if(LedTimeCount2>=8)
{
LedTimeCount2=-16;
//delay(5);
P2=0xfb; //点亮第三只数码管
P0=table[gw];
}
if(LedTimeCount3>=12)
{
LedTimeCount3=-16;
//delay(5);
P2=0xf7; //点亮第四只数码管
P0=table[0]; //第四只数码管一直显示0
}
if(LedTimeCount4>=16)
{
LedTimeCount1=0;
LedTimeCount2=0;
LedTimeCount3=0;
LedTimeCount4=0;
//delay(5);
}
*/
Time500us=0;
LedTimeCount1++;
LedTimeCount2++;
LedTimeCount3++;
LedTimeCount4++;
if(LedTimeCount1>=4)
{
LedTimeCount1=0;//LED计数器复位
//delay(5);
P2=0xfd; //点亮第二只数码管
P0=table[sw];
if(LedTimeCount2>=8)
{
LedTimeCount2=0;
//delay(5);
P2=0xfb; //点亮第三只数码管
P0=table[gw];
if(LedTimeCount3>=12)
{
LedTimeCount3=0;
//delay(5);
P2=0xf7; //点亮第四只数码管
P0=table[0]; //第四只数码管一直显示0
if(LedTimeCount4>=16)
{
LedTimeCount4=0;
//delay(5);
}
}
}
}
}
}
time.h
#ifndef _TIME_H_
#define _TIME_H_
extern void Timer0Init(void);
extern bit Time500us;
#endif
time.c
#include <reg52.h>
bit Time500us = 0 ; // 500us时间片
/**********定时器初始化*******************/
void Timer0Init(void)
{
TMOD= 0x01;//定时器 0 工作方式 1
TH0 = 0xfe ; //定时器初始值500us
TL0 = 0x33 ;
TR0 = 1 ;
ET0 = 1 ;
EA = 1 ; //中断允许总控制位
}
void Time0Isr(void) interrupt 1
{
TH0 = 0xfe ; //500us
TL0 = 0x33 ;
Time500us = 1 ; //500uS 时标标志位置位
}
main.c
#include<reg52.h>
#include <intrins.h>
#include "macroandconst.h"
#include "led.h"
//#include "delay.h"
#include "time.h"
sbit wr=P3^6;
sbit rd=P3^7;
static uint16 TimeCount = 0 ; //计数器 typedef int int16; 有符号的
void main(void)
{
uchar i;
Timer0Init();
while(1)
{
wr=0; //在片选信号CS为低电平情况下(由于CS接地,所以始终为低电平),
_nop_(); //WR由低电平到高电平时,即上升沿时,AD开始采样转换
wr=1;
if(Time500us)
{ // delay(1); //延时1ms,等待采样转换结束,延时函数 delay(1)延时0.992ms,大约为1ms
// P1=0xff; //这条语句不能少,我也还不知道为什么
Time500us=0; //
TimeCount++;
if(TimeCount>=2)
{
TimeCount=0; //计数器复位
rd=0; //将RD脚置低电平后,再延时大于135ns左右(这里延时1us),
_nop_(); //即可从DB脚读出有效的采样结果,传送到P1口
for(i=0;i<10;i++) //刷新显示一段时间
display(P1); //显示从DB得到的数字量
}
}
}
}
0804_serial port的更多相关文章
- Exception thrown by the agent : java.rmi.server.ExportException: Port already in use
今天有个应用一直起不来,感觉配置都对啊,奇了怪了.看日志发现如下: STATUS | wrapper | 2017/01/04 08:09:31 | Launching a JVM...INFO | ...
- IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551): java.net.SocketException
学习Java Servlet时,从Wrox上下载了示例代码,准备run/debug时发现以下错误: Error running Tomcat 8.5.8: Unable to open debugge ...
- Altium Designer 的entry sheet ,offsheet和port作用(转载)
1.图纸结构 图纸包括两种结构关系: 一种是层次式图纸,该连接关系是纵向的,也就是某一层次的图纸只能和相邻的上级或下级有关系: 另一种是扁平式图纸,该连接关系是横向的,任何两张图纸之间都可以建立信号连 ...
- gen_server port 调用receive_match 问题
问题由来 前些天对系统做了一个优化,将原来从queue 轮询刷出数据后每条消息一个 spawn 进程单独处理,修改为批量刷出.一条一条刷轮询刷 queue 存在问题:刷queue 进程太多时,占用CP ...
- Serial Port Programming on Linux(转载)
This is a tutorial on how to program the Serial Ports on your Linux box.Serial Ports are nice little ...
- Serial Port Programming using Win32 API(转载)
In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...
- FTP Service mode : PORT & PASV
PORT Mode: 1. FTP client use TCP port 1026 for command to FTP server command port 212. FTP server us ...
- WCF service 获取 client 端的 IP 和 port (转)
转帖记录一下,以便日后使用. 主要使用是.NET3.5里的服务端上下文的消息实例的RemoteEndpointMessageProperty属性,获取客户端地址信息.但是限制 的绑定是HTTP.TCP ...
- Could not open Selected VM debug port (8700) (转)
Could not open Selected VM debug port (8700) 2014年11月14日 ⁄ 综合 ⁄ 共 446字 ⁄ 字号 小 中 大 ⁄ 评论关闭 在运行项目的时候, ...
随机推荐
- Xshell远程连接Linux系统
一般来说我们连接Linux,会使用到一些远程连接工具 比如:Xshell和Xftp Xshell:远程连接linux系统 Xftp:远程在Linux系统中上传或下载文件 Xshell和Xftp百度云链 ...
- D. Feeding Chicken(构造)
题目大意:将k个鸡放到一个n*m的矩阵中,要求每个鸡所占的rice的个数只差最小 题解:构造,设一共有cnt个rice,可以分cnt/k个,即每一只鸡要么占用cnt/k个rice,要么占cnt/k+1 ...
- [Laravel框架学习一]:Laravel框架的安装以及 Composer的安装
1.先下载Composer-Setup.exe,下载地址:下载Composer .会自动搜索PHP.exe的安装路径,如果没有,就手动找到php路径下的php.exe. 2.在PHP目录下,打开php ...
- ubuntu16.04-交叉编译opencv3.4.6
0.前言 在要移植opecv和SeetaFaceEngine-master到ARM板子上运行的所有步骤之前,有几点需要注意的: 查看板子运行的Kernel版本 交叉编译工具链的gcc版本,关键就是工具 ...
- Python数据分析入门与实践 学习
pandas是一个Python语言的软件包,在我们使用Python语言进行机器学习编程的时候,这是一个非常常用的基础编程库.本文是对它的一个入门教程.pandas提供了快速,灵活和富有表现力的数据结构 ...
- php sprintf() 函数把格式化的字符串写入一个变量中。
来源:https://blog.csdn.net/zxh1220/article/details/79709207 HP sprintf() 函数用到的参数 printf — 输出格式化字符串 spr ...
- tp5 auth权限的原理
我的一些个人理解,还是有些不懂的地方,有错误请指正,谢谢!!! class Auth{ //默认配置 protected $_config = array( 'auth_on' => true, ...
- 解决linux(ubuntu18)下无法挂载ntfs磁盘,并读写挂载硬盘
首先需要有ntfs-3g,没有的话sudo apt-get install ntfs-3g 挂载硬盘: chen@ilaptop:/$ sudo mount -o rw,remount /dev/sd ...
- opencv-3-图片存储与相对路径
opencv-3-图片存储与相对路径 opencvqtC++ 在上一篇文章opencv 显示第一副图像 中, 我们完成了一副图像的显示, 包括使用VS,和QT 进行显示.. 本文将展示如何进行图像的显 ...
- [故障解决]图文:windows apache无法启用 端口被占用
windows apache无法启用 端口被占用 1 XAMPP Error: Apache shutdown unexpectedly 无法启动apache,显示的log为: 2 查了一下端口, 通 ...