想用52单片机做个流水灯有水滴效果的,需要哪些材料?

想用52单片机做个流水灯有水滴效果的,需要哪些材料?,第1张

一片52单片机, 晶振一件 ,电容104 2件, 电阻 300欧两件,按钮开关两件, 发光二极管若干 面包板或者PCB空板一块 焊锡一米 电烙铁一件 电池三节(15v)如要有音效 则需要蜂鸣器一件。三级管一件-

看一下库文件里面的此份文件《stm32f10x_stdperiph_lib_umchm》。
对于启动文件需要根据实际的芯片来选择,如果是大容量的则选择“startup_stm32f10x_hds”,例程能够正常是因为有相应的文件中有预处理程序。
How to use the Standard Peripherals Library
Create a project and setup all your toolchain's start-up files (or use the template project provided within the Library, under
Project\STM32F10x_StdPeriph_Template)
Select the corresponding startup file depending of the used device:
- startup_stm32f10x_ld_vls: for STM32 Low density Value line devices
- startup_stm32f10x_lds: for STM32 Low density devices
- startup_stm32f10x_md_vls: for STM32 Medium density Value line devices
- startup_stm32f10x_mds: for STM32 Medium density devices
- startup_stm32f10x_hds: for STM32 High density devices
- startup_stm32f10x_xls: for STM32 XL density devices
- startup_stm32f10x_cls: for STM32 Connectivity line devices
The Library entry point is stm32f10xh (under Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x), user has to include it in the application main and configure it:
Select the target product family to be used, comment/uncomment the right define:
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)
/ #define STM32F10X_LD / /!< STM32F10X_LD: STM32 Low density devices /
/ #define STM32F10X_LD_VL / /!< STM32F10X_LD_VL: STM32 Low density Value Line devices /
/ #define STM32F10X_MD / /!< STM32F10X_MD: STM32 Medium density devices /
/ #define STM32F10X_MD_VL / /!< STM32F10X_MD_VL: STM32 Medium density Value Line devices /
/ #define STM32F10X_HD / /!< STM32F10X_HD: STM32 High density devices /
#define STM32F10X_XL /!< STM32F10X_CL: STM32 XL-density devices /
/ #define STM32F10X_CL / /!< STM32F10X_CL: STM32 Connectivity line devices /
#endif
Then user has the choice to use or not the Peripheral’s Drivers
- Case1: application code based on Standard Peripheral’s drivers API (files under Libraries\STM32F10x_StdPeriph_Driver)
- Uncomment #define USE_PERIPH_LIBRARY (default)
- In stm32f10x_confh file, select the peripherals to include their header file
- Use Peripheral’s drivers API to build the application; refer to next section for more information
- In addition to the Peripheral’s drivers you can reuse/adapt the rich set of examples available within the Library to speed
your development, this allow you to started within few hours Refer to the complete list of available examples
- Case2: application code based on Peripheral’s registers direct access
- Comment #define USE_PERIPH_LIBRARY
- Use Peripheral’s registers structure and bits definition available within stm32f10xh to build the application
Add the system_stm32f10xc (under Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) file in your application, this file provide functions to setup the STM32 system: configure the PLL, system clock and initialize the Embedded Flash Interface This file provides multiple choice for the system clock frequency, you can selected the frequency needed for your application from the list below (common frequencies that covers the major of the applications):
#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL)
/ #define SYSCLK_FREQ_HSE HSE_Value /
#define SYSCLK_FREQ_24MHz 24000000
#else
/ #define SYSCLK_FREQ_HSE HSE_Value /
/ #define SYSCLK_FREQ_24MHz 24000000 /
/ #define SYSCLK_FREQ_36MHz 36000000 /
/ #define SYSCLK_FREQ_48MHz 48000000 /
/ #define SYSCLK_FREQ_56MHz 56000000 /
#define SYSCLK_FREQ_72MHz 72000000
#endif
Note: The System clock configuration functions provided within this file assume that:
- For Low-density Value line, Low-density, Medium-density Value line, Medium-density and High-density devices an external 8MHz crystal is used to drive the System clock
- For Connectivity line devices an external 25MHz crystal is used to drive the System clock
If you are using different crystal you have to change the value of the define HSE_VALUE in stm32f10xh file and adapt those functions
accordingly

#include<reg51h>
sbit S1=P1^4;
sbit S2=P1^5;
sbit S3=P1^6;
sbit S4=P1^7;
unsigned char keyval;
void led_delay(void)
{
unsigned char i,j;
for(i=0;i<250;i++)
for(j=0;j<250;j++)
;
}
void delay20ms(void)
{
unsigned char i,j;
for(i=0;i<100;i++)
for(j=0;j<60;j++)
;
}
/正向流水点亮LED/
void forward(void)
{
P3=0xfe;
led_delay();
P3=0xfd;
led_delay();
P3=0xfb;
led_delay();
P3=0xf7;
led_delay();
P3=0xef;
led_delay();
P3=0xdf;
led_delay();
P3=0xbf;
led_delay();
P3=0x7f;
led_delay();
P3=0xff;
P3=0xfe;
led_delay();
}
/反向流水点亮LED/
void backward(void)
{
P3=0x7f;
led_delay();
P3=0xbf;
led_delay();
P3=0xdf;
led_delay();
P3=0xef;
led_delay();
P3=0xf7;
led_delay();
P3=0xfb;
led_delay();
P3=0xfd;
led_delay();
P3=0xfe;
led_delay();
}
/关闭所有LED/
void stop(void)
{
P3=0xff; //关闭8个LED
}
/闪烁点亮LED/
void flash(void)
{
P3=0xff; //关闭8个LED
led_delay();
P3=0x00; //点亮8个LED
led_delay();
}
void main(void)
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
keyval=0;
while(1)
{
switch(keyval)
{
case 1:forward();
break;
case 2:backward();
break;
case 3:stop();
break;
case 4: flash();
break;
}
}
}
void Time0_serve(void) interrupt 1 using 1
{
if((P1&0xf0)!=0xf0)
{
delay20ms();
if(S1==0)
keyval=1;
if(S2==0)
keyval=2;
if(S3==0)
keyval=3;
if(S4==0)
keyval=4;
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
}
用 AT89C51


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13066621.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-30
下一篇 2023-05-30

发表评论

登录后才能评论

评论列表(0条)

保存