-
-
0#include "reg51.h" #define uchar unsigned char #define uint unsigned int sbit k1=P1^4;//设置 sbit k2=P1^5;//加 //数码管编码 uchar code smgduan[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; uchar time=0,mode=0;//系统变量 uchar shi=12,fen=0,miao=0;//计时 //延时 void delay(uint i) { while(i--); } void main()//主函数 { uchar a=0,k=0; TMOD|=0X01; TH0=(65536-50000)/256;//50ms TL0=(65536-50000)%256; ET0=1;//打开定时器0中断允许 EA=1;//打开总中断 TR0=1;//打开定时器 while(1) { if(!k1 &&(k!=1))//设置切换 { k=1; if(mode<6) mode++;
-
1
-
0
-
1
-
0
-
0
-
1
-
2//音符半周期us 1908 1706 1520 1436 1276 1136 1012 956 854 760 718 638 568 506 478 426 380 358 320 284 254 #include <reg51.h> #include <intrins.h> #include "lcd1602.h" #define uchar unsigned char #define uint unsigned int sbit K1=P1^0;//按钮定义 sbit K2=P1^1; sbit K3=P1^2; sbit K4=P1^3; sbit K5=P1^4; sbit beep=P2^7;//蜂鸣器 uchar ge_num=1;//歌曲编号 //音符半周期us 1908 1706 1520 1436 1276 1136 1012 956 854 760 718 638 568 506 478 426 380 358 320 284 254 //半周期 uint code music[22]={0x0fff,1908,1706,1520,1436,1276,1136,1012,956,854,760,718,638,568,
-
027C64存储器LED显示ABCD的代码
-
2汇编程序: ORG 0000H //正弦波 wave1: DB 00H,18H,24H,24H,7EH,42H,42H,00H,00H,38H,24H,24H,38H,24H,24H,38H wave2: DB 00H,38H,44H,40H,40H,40H,44H,38H,00H,78H,44H,44H,44H,44H,44H,78H wave3: DB 10H,10H,0FCH,10H,28H,44H,82H,00H,00H,10H,10H,54H,92H,10H,30H,10H wave4: DB 00H,10H,10H,7CH,10H,10H,0FEH,00H,10H,10H,0FEH,10H,38H,54H,92H,10H END 用法:将程序保存到txt,然后改名main.ASM,编译 双击27C64将生成的HEX文件导入。 运行仿真
-
0#include "reg51.h" //此文件中定义了单片机的一些特殊功能寄存器 typedef unsigned int u16; //对数据类型进行声明定义 typedef unsigned char u8; sbit beep=P1^0;//蜂鸣器 sbit key1=P1^1;//功能切换.时间/闹钟 sbit key2=P1^2;//选择时、分、秒(按第4次确认) sbit key3=P1^3;//加 sbit key4=P1^4;//减 sbit key5=P1^5;//停止响铃 u8 mode=0;//模式。0时间1闹钟 u8 cixu=0;//设置模式。1时2分3秒 u8 time=0;//计时变量,1s u8 beep_flag=0,beep_flag0=0;//蜂鸣器标志 u8 xian1[8]={0,0,0x40,0,0,0x40,0,0};//显存.时间 u8 xian2[8]={
-
0mode equ 30H;输入模式、结果显示模式 key equ 39H;键值 ;31H-34H输入数据 ;35H-38H结果 ORG 0000H AJMP MAIN ORG 0003H AJMP INT00 ORG 0030H MAIN: SETB IT0//初始化INT0 SETB EX0 SETB EA MOV DPTR,#TABLE1;数码管编码地址 MOV mode,#0 /*MOV A,#7 MOV 31H,A MOV A,#6 MOV 32H,A MOV A,#1 MOV 33H,A MOV A,#2 MOV 34H,A*/ START: //按键检测 MOV A,#0C0H MOV P1,A MOV A,#0FFH MOV P3,A //显示输入数据 MOV A,mode JNZ ST1 MOV A,31H MOVC A,@A+DPTR;读取编码 MOV P0,A CLR P2.0 //位选 ACALL DELAY SETB P2.0 MOV A,32H MOVC A,@A+DPTR;读取编码 MOV P0,A CLR P2.1 //位选 ACALL DELAY
-
0
-
01、输出直流电压,电压范围0-5V,按键设置电压的大小 2、输出交流电压,频率20Hz,振幅0-5V,振幅通过按键调节 3、数码管显示每个通道的电压 #include "reg51.h" #include "absacc.h" #define uchar unsigned char #define uint unsigned int #define DAC1 XBYTE[0XFEFF]//定义DAC0832地址 #define DAC2 XBYTE[0XFDFF] sbit smg1=P3^0;//数码管 sbit smg2=P3^1; sbit smg3=P3^2; sbit smg4=P3^3; sbit k1=P2^4;//按钮 sbit k2=P2^5; sbit k3=P2^6; sbit k4=P2^7; uchar code smgduan0[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//显示
-
1
-
0
-
0#include "reg51.h" #define uchar unsigned char #define uint unsigned int sbit rs=P2^0; //1602数据/命令选择引脚 sbit rw=P2^1; //1602读写引脚 sbit e =P2^2; //1602使能引脚 uchar code sex[]={ //性别 'M','F','F','M','M','M','F','M', 'M','F','M','M','F','F','F','M' }; uchar code dat[16][16]={ " Zhang SanSi ", " Wang yue ", " Chen xia ", " Li ya hui ", " huiiuhiuhjh ", " kjkjghfg ", &quo
-
0
-
0
-
0完成步进电机的驱动顺时针旋转设计,并通过led指示 扩展:能够通过按键完成顺时针、逆时针、加速、减速旋转设计 并显示转速(LED显示) #include "reg51.h" #include "intrins.h" #define uchar unsigned char #define uint unsigned int sbit AA=P2^4;//步进电机 sbit BB=P2^5; sbit CC=P2^6; sbit DD=P2^7; sbit k1=P1^0;//按钮 sbit k2=P1^1; sbit k3=P1^2; sbit k4=P1^3; sbit k5=P1^4; sbit k6=P1^5; sbit smg1=P2^0;//数码管引脚 sbit smg2=P2^1; uchar code smgduan0[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//显示0~9,
-
0#include "reg51.h" #include "lcd1602.h" #define uchar unsigned char #define uint unsigned int sbit AA=P2^4;//步进电机 sbit BB=P2^5; sbit CC=P2^6; sbit DD=P2^7; sbit k1=P1^0;//按钮 sbit k2=P1^1; sbit k3=P1^2; sbit k4=P1^3; sbit k5=P1^4; sbit k6=P1^5; uchar flag=0,fang=0;//方向控制 uchar speed=0,time=0;//速度控制0-9 uchar start=0;//启动 uchar sec=0; uchar disp1[]="sudu:0 ";//速度 //主函数 void main() { init_1602(); TMOD|=0X01; TH0=(65536-10000)/256; TL0=(65536-10000)%256; ET0=1;//打开定时器0中断允许 EA=1;//打开总中断 TR0=1;//打
-
0#include "reg51.h" #include "74hc595.h" #define uchar unsigned char//重定义 #define uint unsigned int sbit k1=P3^2;//按钮 sbit k2=P3^3; sbit k3=P3^4; sbit k4=P3^5; uchar time=0,sec=0,mode=0;//定时 uchar flag=0;//显示控制 uchar disp1[40]; uchar code disp[]={//10行 0x04,0x18,0x60,0x18, 0x04,0x00,0x3C,0x54, 0x54,0x48,0x00,0x7C, 0x40,0x40,0x00,0x00, 0x38,0x44,0x44,0x44, 0x00,0x38,0x44,0x44, 0x38,0x00,0x70,0x08, 0x70,0x08,0x70,0x00, 0x00,0x5E,0x00,0x5E, 0x00,0x00,0x00,0x00 }; void delay_uint(uint i)//延时 { while(i--); } //显示 void display() { uchar i; for(i=0;
-
0
-
0#include<reg51.h> #include<absacc.h> #define COM8279 XBYTE[0x7fff] #define DAT8279 XBYTE[0x7eff] #define uchar unsigned char uchar code table[]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; uchar idata keybuffer[3]={0,0,0}; sbit clflag=ACC^7; uchar key; uchar Keyflag; uchar p=0; void delay(uchar x) { uchar i; for(i=0;i<x;i++); } void Display() { uchar i; COM8279=0X90; for(i=0;i<3;i++) { COM8279=i+0x80; DAT8279=table[keybuffer[i]]; delay(10); } } void Disp(d) { COM8279=0X90; COM8279=0x80; DAT8279=table[key]; delay(10); } void Key_0(void) i
-
0【H文件】 #ifndef __DS1302_H_ #define __DS1302_H_ //---包含头文件---// #include<reg51.h> #include<intrins.h> //---重定义关键词---// #ifndef uchar #define uchar unsigned char #endif #ifndef uint #define uint unsigned int #endif //---定义ds1302使用的IO口---// sbit DSIO=P2^7; sbit RST=P2^5; sbit SCLK=P2^6; //---定义全局函数---// void Ds1302Write(uchar addr, uchar dat); uchar Ds1302Read(uchar addr); void Ds1302Init(); void Ds1302ReadTime(); //---加入全局变量--// extern uchar TIME[7];//加入全局变量 #endif 【C文件】 #include"ds1302.h"
-
0#include "reg51.h" #include "lcd1602.h" #define uchar unsigned char #define uint unsigned int sbit out1=P2^6;//输出 uint freq1=10;//频率 uchar pwm1=50,time1=0;//占空比 uchar set0=0,set1=0; uchar disp1[]="Fre:0000Hz"; uchar disp2[]="PWM:00%"; uchar flag=0; uint num=0; //显示函数 void xian() { disp1[4]=freq1/1000+0x30; disp1[5]=freq1%1000/100+0x30; disp1[6]=freq1%100/10+0x30; disp1[7]=freq1%10+0x30; disp2[4]=pwm1/10+0x30; disp2[5]=pwm1%10+0x30; write_string(1,0,disp1); write_string(2,0,disp2); } //计算通道1周期 void zhou1() { unsigned lon
-
0#include "reg51.h" #include "lcd1602.h" #define uchar unsigned char #define uint unsigned int sbit out1=P2^6;//输出 uint freq1=10;//频率 uchar pwm1=50,time1=0;//占空比 uchar set0=0,set1=0; uchar disp1[]="Fre:0000Hz"; uchar disp2[]="PWM:00%"; uchar flag=0; uint num=0; //显示函数 void xian() { disp1[4]=freq1/1000+0x30; disp1[5]=freq1%1000/100+0x30; disp1[6]=freq1%100/10+0x30; disp1[7]=freq1%10+0x30; disp2[4]=pwm1/10+0x30; disp2[5]=pwm1%10+0x30; write_string(1,0,disp1); write_string(2,0,disp2); } //计算通道1周期 void zhou1() { unsigned lon
-
2
-
0单5V电源供电,控制10只串联的白光LED灯。 要求设置至少2个按键,分别代表亮度增强键和亮度减弱键,单片机采集对应的键值后送出至数/模转换器来调节LED的电压,最终实现对串联白光LED灯亮度的调节。 #include "reg51.h" #define uchar unsigned char #define uint unsigned int sbit k1=P1^0;//按钮 sbit k2=P1^1; sbit smg1=P3^0;//数码管 sbit smg2=P3^1; uchar code smgduan[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//显示0~9,无小数点 //延时 void delay(uint i) { while(i--); } //主函数 void main() {
-
0#include "reg51.h" #define uchar unsigned char #define uint unsigned int //数码管编码 uchar code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar key=0; uchar key_scan()//按键检测 { uchar i; i=0; P1=0x7f; switch(P1)//检测第1行 { case 0x7e:i=4;break; case 0x7d:i=3;break; case 0x7b:i=2;break; case 0x77:i=1; } P1=0xBf; switch(P1)//检测第2行 { case 0xBe:i=8;break; case 0xBd:i=7;break; case 0xBb:i=6;break; case 0xB7:i=5; } P1=0xDf; switch(P1)//检测第3行 { case 0xDe:i=12;break; case 0xDd:i=11;break; case 0xDb:i=10;break; case 0xD7:i=9; } P1=0xEf;
-
0#include "reg51.h" #define uchar unsigned char #define uint unsigned int sbit rs=P2^0; //1602数据/命令选择引脚 sbit rw=P2^1; //1602读写引脚 sbit e =P2^2; //1602使能引脚 sbit in=P3^2;//脉冲输入 uint time=0;//计时 uint miao=0; uchar disp[]="00.00s"; //延时函数 void delay_uint(uint i) { while(i--); } //1602命令函数 void write_com(uchar com) { e=0; rs=0; rw=0; P0=com; delay_uint(20); e=1; delay_uint(20); e=0; } //1602写数据函数 void write_data(uchar dat) { e=0; rs=1; rw=0; P0=dat; delay_uint(20); e=1; delay_uint(20); e=0; } //设置当前行
-
0#include <REGX52.H> #include "intrins.h" #include "FFT.h" #include <math.h> #define uchar unsigned char #define uint unsigned int sbit smg1=P3^0;//LED sbit smg2=P3^1; sbit smg3=P3^2; uchar Mat[8]; void delay(uchar i) { while(i--); } void imshow(uchar *p) { uchar i=0; for(i=0;i<8;i++) { P1=0; switch(i) { case 7:smg3=1;smg2=1;smg1=1;break; case 6:smg3=1;smg2=1;smg1=0;break; case 5:smg3=1;smg2=0;smg1=1;break; case 4:smg3=1;smg2=0;smg1=0;break; case 3:smg3=0;smg2=1;smg1=1;break; case 2:smg3=0;smg2=1;smg1=0;break; case 1:smg3=0;smg2=0;smg1=1;break; case 0:smg3=0;
-
0#include "reg51.h" #include <absacc.h> #define uchar unsigned char #define uint unsigned int #define sec XBYTE[0x7f00] #define seca XBYTE[0x7f01] #define min XBYTE[0x7f02] #define mina XBYTE[0x7f03] #define hour XBYTE[0x7f04] #define houra XBYTE[0x7f05] #define day XBYTE[0x7f06] #define date XBYTE[0x7f07] #define month XBYTE[0x7f08] #define year XBYTE[0x7f09] #define RA XBYTE[0x7f0A] #define RB XBYTE[0x7f0B] #define RC XBYTE[0x7f0C] #define RD XBYTE[0x7f0D] sbit smg1=P1^0;//数码管 sbit smg2=P1^1; sbit smg3=P1^2; sbit smg4=P1^3; sbit k1=P1^4;//按钮 sbit k2=P1^5; //数码