基于STM32的波形发生器.docx
- 文档编号:1178969
- 上传时间:2022-10-18
- 格式:DOCX
- 页数:16
- 大小:16.49KB
基于STM32的波形发生器.docx
《基于STM32的波形发生器.docx》由会员分享,可在线阅读,更多相关《基于STM32的波形发生器.docx(16页珍藏版)》请在冰豆网上搜索。
基于STM32的波形发生器
#include"stm32f10x.h"
#include"pcf8591.h"
voidRCC_Config(void);
voidGPIO_Config(void);
externuint8_tpcf8591_read(uint8_tcmd);
voidDelay_d(__IOuint32_tt);
externboolpcf8591_write(uint8_tcmd,uint8_t*data,uint32_tlength);
voidTimeDecrement(void);
voidDelay_us(__IOuint32_tt);
externuint32_tcounter;
static__IOuint32_tTimingDelay;
voidkey_delay(__IOuint32_tt);
uint8_tkey_scan(void);
uint8_tkey_fscan(void);
uint8_tans=0;
floatvol=0;
uint8_tSine12bit[256]={0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95,0x98,0x9c,0x9f,0xa2,0xa5,0xa8,0xab,0xae,0xb0,0xb3,
0xb6,0xb9,0xbc,0xbf,0xc1,0xc4,0xc7,0xc9,0xcc,0xce,0xd1,0xd3,0xd5,0xd8,0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,
0xed,0xef,0xf0,0xf2,0xf3,0xf4,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfc,0xfd,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xfe,0xfe,0xfd,0xfc,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf3,0xf2,0xf0,0xef,0xed,0xec,0xea,0xe8,
0xe6,0xe4,0xe3,0xe1,0xde,0xdc,0xda,0xd8,0xd6,0xd3,0xd1,0xce,0xcc,0xc9,0xc7,0xc4,0xc1,0xbf,0xbc,0xb9,0xb6,0xb4,0xb1,0xae,
0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x99,0x96,0x92,0x8f,0x8c,0x89,0x86,0x83,0x80,0x7d,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x64,
0x61,0x5e,0x5b,0x58,0x55,0x52,0x4f,0x4c,0x49,0x46,0x43,0x41,0x3e,0x3b,0x39,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27,0x25,0x23,
0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x14,0x12,0x10,0xf,0xd,0xc,0xb,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x3,0x2,0x1,0x1,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x2,0x3,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xc,0xd,0xe,0x10,0x12,0x13,0x15,0x17,
0x18,0x1a,0x1c,0x1e,0x20,0x23,0x25,0x27,0x29,0x2c,0x2e,0x30,0x33,0x35,0x38,0x3b,0x3d,0x40,0x43,0x46,0x48,0x4b,0x4e,0x51,
0x54,0x57,0x5a,0x5d,0x60,0x63,0x66,0x69,0x6c,0x6f,0x73,0x76,0x79,0x7c};
uint8_tsq12bit[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50};//方波
uint8_ttrangle[32]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,
30,28,26,24,22,20,18,16,14,12,10,8,6,4,2};//三角波
uint8_txiebo[32]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,
34,36,38,40,42,44,46,48,50,52,54,56,58,60,62};//谐波
uint8_tkey,keyf;
uint8_ti,j;
intmain(void)
{
RCC_Config();
GPIO_Config();
SysTick_Config(72);//1us
while
(1)
{key=key_scan();
keyf=key_fscan();
switch(key%4)
{
case0:
pcf8591_write(0x40,Sine12bit,256);
break;
case1:
pcf8591_write(0x40,sq12bit,32);
break;
case2:
pcf8591_write(0x40,trangle,32);
break;
case3:
pcf8591_write(0x40,xiebo,32);
break;
default:
break;
}
switch(keyf%5)
{
case0:
if(key%4==0)
{
pcf8591_write(0x40,Sine12bit,256);
}
elseif(key%4==1)
{
pcf8591_write(0x40,sq12bit,32);
}
elseif(key%4==2)
{
pcf8591_write(0x40,trangle,32);
}
elseif(key%4==3)
{
pcf8591_write(0x40,xiebo,32);
}
break;
case1:
if(key%4==0)
{
pcf8591_write(0x40,Sine12bit,256);
}
elseif(key%4==1)
{
pcf8591_write(0x40,sq12bit,32);
}
elseif(key%4==2)
{
pcf8591_write(0x40,trangle,32);
}
elseif(key%4==3)
{
pcf8591_write(0x40,xiebo,32);
}
break;
case2:
if(key%4==0)
{
pcf8591_write(0x40,Sine12bit,256);
}
elseif(key%4==1)
{
pcf8591_write(0x40,sq12bit,32);
}
elseif(key%4==2)
{
pcf8591_write(0x40,trangle,32);
}
elseif(key%4==3)
{
pcf8591_write(0x40,xiebo,32);
}
break;
case3:
if(key%4==0)
{
pcf8591_write(0x40,Sine12bit,256);
}
elseif(key%4==1)
{
pcf8591_write(0x40,sq12bit,32);
}
elseif(key%4==2)
{
pcf8591_write(0x40,trangle,32);
}
elseif(key%4==3)
{
pcf8591_write(0x40,xiebo,32);
}
break;
case4:
if(key%4==0)
{
pcf8591_write(0x40,Sine12bit,256);
}
elseif(key%4==1)
{
pcf8591_write(0x40,sq12bit,32);
}
elseif(key%4==2)
{
pcf8591_write(0x40,trangle,32);
}
elseif(key%4==3)
{
pcf8591_write(0x40,xiebo,32);
}
break;
default:
break;
}
}
}
voidDelay_us(__IOuint32_tt)
{
TimingDelay=t;
while(TimingDelay!
=0);
}
voidTimeDecrement(void)
{
if(TimingDelay!
=0)
{
TimingDelay--;
}
}
voidRCC_Config(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
}
voidGPIO_Config(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;//SDASCL
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_2|GPIO_Pin_3;//按键
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//LED
GPIO_InitStructure.GPIO_Spe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 STM32 波形 发生器