89s52单片机的硬件资源基本使用
2010-04-17 16:12
447 查看
1.最典型、基本的定时器T0的初始化方法
#include<reg51.h>
sbit b=P1^1;
void T0isr(void) interrupt 1
{
TL0=0X0C;
TH0=0X0F0;
b=~b;
}
void main()
{
b=0;
TMOD=0X00;
TL0=0X0C;
TH0=0X0F0;
TR0=1;
ET0=1;
EA=1;
while(1)
{}
}
2.最基本初始化串行口模式1
#include<reg52.h>
void main()
{
int ch;
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TL1=0XF4;
TH1=0XF4;
ES=0;
TR1=1;
SBUF=0X79;
while(TI)
{
TI=0;
}
while(RI)
{
ch=SBUF;
RI=0;
}
}
3.字符串输入输出的仿真
#include<stdio.h>
#include<reg52.h>
void main()
{
char ch;
SCON=0x50;
TMOD|=0x20;
PCON|=0x80;
TL1=0xf4;
TH1=0xf4;
IE|=0X90;
TR1=1;
printf("please input a char!/n");
while((ch=_getkey())!=0x0d)
{
printf("the in char=%c,the hex number=%bx/n",ch,ch);
}
}
4.中断基本设置
#include<reg52.h>
void ISR0(void) interrupt 0
{
P1=P1+1;
}
void ISR1(void) interrupt 2
{
P2=~P2;
}
void main()
{
IP=0X05;
IT0=1;
IT1=1;
EX0=1;
EX1=1;
EA=1;
P1=0;
while(1){}
}
5.看门狗的设置
#include<reg52.h>
sfr WDTRST=0XA6;
void main()
{
int i;
WDTRST=0X1E;
WDTRST=0XE1;
while(1)
{
if(P1==0x01)
{
for(i=0;i<100;i++);
}
else if(P1==0x02)
{
for(i=0;i<10000;i++);
}
else
{
}
WDTRST=0X1E;
WDTRST=0XE1;
}
}
6.寄存器仿真
ORG 0000H
JMP START
ORG 1000H
START: MOV R0,#00H
MOV R1,#11H
MOV R2,#22H
MOV R3,#33H
MOV P0,R0
MOV P1,R1
MOV P2,R2
MOV P3,R3
JMP START
END
8.低功耗仿真
#include<reg52.h>
#include<stdio.h>
void main(void)
{
while(1)
{
if(P1==0x01)
{
PCON=0X01;
}
else if(P1==0X02)
{
PCON=0X02;
}
else{}
}
}
#include<reg51.h>
sbit b=P1^1;
void T0isr(void) interrupt 1
{
TL0=0X0C;
TH0=0X0F0;
b=~b;
}
void main()
{
b=0;
TMOD=0X00;
TL0=0X0C;
TH0=0X0F0;
TR0=1;
ET0=1;
EA=1;
while(1)
{}
}
2.最基本初始化串行口模式1
#include<reg52.h>
void main()
{
int ch;
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TL1=0XF4;
TH1=0XF4;
ES=0;
TR1=1;
SBUF=0X79;
while(TI)
{
TI=0;
}
while(RI)
{
ch=SBUF;
RI=0;
}
}
3.字符串输入输出的仿真
#include<stdio.h>
#include<reg52.h>
void main()
{
char ch;
SCON=0x50;
TMOD|=0x20;
PCON|=0x80;
TL1=0xf4;
TH1=0xf4;
IE|=0X90;
TR1=1;
printf("please input a char!/n");
while((ch=_getkey())!=0x0d)
{
printf("the in char=%c,the hex number=%bx/n",ch,ch);
}
}
4.中断基本设置
#include<reg52.h>
void ISR0(void) interrupt 0
{
P1=P1+1;
}
void ISR1(void) interrupt 2
{
P2=~P2;
}
void main()
{
IP=0X05;
IT0=1;
IT1=1;
EX0=1;
EX1=1;
EA=1;
P1=0;
while(1){}
}
5.看门狗的设置
#include<reg52.h>
sfr WDTRST=0XA6;
void main()
{
int i;
WDTRST=0X1E;
WDTRST=0XE1;
while(1)
{
if(P1==0x01)
{
for(i=0;i<100;i++);
}
else if(P1==0x02)
{
for(i=0;i<10000;i++);
}
else
{
}
WDTRST=0X1E;
WDTRST=0XE1;
}
}
6.寄存器仿真
ORG 0000H
JMP START
ORG 1000H
START: MOV R0,#00H
MOV R1,#11H
MOV R2,#22H
MOV R3,#33H
MOV P0,R0
MOV P1,R1
MOV P2,R2
MOV P3,R3
JMP START
END
8.低功耗仿真
#include<reg52.h>
#include<stdio.h>
void main(void)
{
while(1)
{
if(P1==0x01)
{
PCON=0X01;
}
else if(P1==0X02)
{
PCON=0X02;
}
else{}
}
}
相关文章推荐
- Keil 中如何使用 STM32F4xx 单片机硬件浮点单元
- Windows编程 基本资源的使用 如何在窗口中输出一些简单的文本
- Win32SDK基本 RC资源的使用
- 让你对硬件资源使用情况一目了然——推荐一个跨平台的命令行监控工具Glances
- AVR单片机最小系统 基本硬件线路与分析
- webpack学习之一,基本使用和管理资源
- (一)关于SWT程序的基本架构,如何使用控件以及使用Image,Font,Color等图形资源内容
- 奶爸业余单片机学习之:定时器中断的使用方法——进入中断TF0(TF1)值硬件自动重置
- STC单片机硬件PWM的使用分析
- Linux硬件资源管理与外设设备使用、系统运行机制及用户管理
- springboot基本使用笔记----静态资源(js ,css ...)路径
- TextMeshProUGUI的基本使用方法(资源创建、材质、表情等)
- android基本的资源目录结构组成和使用场景
- andorid系统使用硬件资源_传感器1
- 单片机实验——0到60秒的计时器(使用硬件中断方式实现)
- AVR单片机最小系统 基本硬件线路与分析
- 18 如何使用go来采集windows的基本硬件信息后发送到CMDB的服务器上
- 单片机硬件==PCB的使用注意事项
- NHibernate的基本使用、快速入门 - Microsoft.NET开发框架应用资源(zhuan)
- 102-资源打包,内存分配,内存泄漏,私有API,硬件信息的获取,使用imageName加载图片和使用imageWithContentsOfFile加载图片的场合优缺点及内存分析