完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
***it key0 = P3^0; ***it key1 = P3^1; ***it key2 = P3^2; ***it key3 = P3^3; ***it key4 = P3^4; code unsigned char sin_tab[] = { 0x7F,0x82,0x85,0x88,0x8B,0x8F,0x92,0x95,0x98,0x9B,0x9E,0xA1,0xA4,0xA7,0xAA,0xAD ,0xB0,0xB3,0xB6,0xB8,0xBB,0xBE,0xC1,0xC3,0xC6,0xC8,0xCB,0xCD,0xD0,0xD2,0xD5,0xD7 ,0xD9,0xDB,0xDD,0xE0,0xE2,0xE4,0xE5,0xE7,0xE9,0xEB,0xEC,0xEE,0xEF,0xF1,0xF2,0xF4 ,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFB,0xFC,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE ,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFD,0xFC,0xFB,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6 ,0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEB,0xE9,0xE7,0xE5,0xE4,0xE2,0xE0,0xDD,0xDB ,0xD9,0xD7,0xD5,0xD2,0xD0,0xCD,0xCB,0xC8,0xC6,0xC3,0xC1,0xBE,0xBB,0xB8,0xB6,0xB3 ,0xB0,0xAD,0xAA,0xA7,0xA4,0xA1,0x9E,0x9B,0x98,0x95,0x92,0x8F,0x8B,0x88,0x85,0x82 ,0x7F,0x7C,0x79,0x76,0x73,0x6F,0x6C,0x69,0x66,0x63,0x60,0x5D,0x5A,0x57,0x54,0x51 ,0x4E,0x4B,0x48,0x46,0x43,0x40,0x3D,0x3B,0x38,0x36,0x33,0x31,0x2E,0x2C,0x29,0x27 ,0x25,0x23,0x21,0x1E,0x1C,0x1A,0x19,0x17,0x15,0x13,0x12,0x10,0x0F,0x0D,0x0C,0x0A ,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08 ,0x09,0x0A,0x0C,0x0D,0x0F,0x10,0x12,0x13,0x15,0x17,0x19,0x1A,0x1C,0x1E,0x21,0x23 ,0x25,0x27,0x29,0x2C,0x2E,0x31,0x33,0x36,0x38,0x3B,0x3D,0x40,0x43,0x46,0x48,0x4B ,0x4E,0x51,0x54,0x57,0x5A,0x5D,0x60,0x63,0x66,0x69,0x6C,0x6F,0x73,0x76,0x79,0x7C }; //void delay_ms(unsigned int ms) //{ // unsigned char i; // while(ms--) // for(i = 0;i<120;i++); //} #define duan P0 #define wei P2 unsigned char code duan_ma[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92, 0x82,0xf8,0x80,0x90,};//黄板 共阳 unsigned char code wei_ma[]= {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; void led_show_delay_us(unsigned int us)//微秒级的延时 { while(us--); } void led_show_number(unsigned char len,unsigned long int num) { unsigned char n; unsigned char temp[8]; temp[7] = num%100000000/10000000; temp[6] = num%10000000/1000000; temp[5] = num%1000000/100000; temp[4] = num%100000/10000; temp[3] = num%10000/1000; temp[2] = num%1000/100; temp[1] = num%100/10; temp[0] = num%10; if(len>8) len =8; for(n = 0;n wei = wei_ma[n]; duan = duan_ma[temp[n]]; led_show_delay_us(100); } } void main() { unsigned char n,us,vol = 1,sta = 0; while(1) { if(key0 == 0) { while(!key0); vol--; if(vol<1)vol = 1; } if(key1 == 0) { while(!key1); vol++; if(vol>3)vol = 3; } if(key2 == 0) { while(!key2); us--; } if(key3 == 0) { while(!key3); us++; } if(key4 == 0) { while(!key4); sta++; if(sta>4) sta =0; } switch(sta) { case 0: n++; P1 = sin_tab[n]/vol; //正玄波 led_show_delay_us(us); break; case 1: n++; P1 = n/vol; led_show_delay_us(us); //锯齿波 break; case 2: for(n = 0;n<255;n++) { P1 = n/vol; led_show_delay_us(us); } //三角波 for(n = 255;n>0;n--) { P1 = n/vol; led_show_delay_us(us); } break; case 3: P1 = n/vol; led_show_delay_us(us); //方波 P1 = ~n/vol; led_show_delay_us(us); break; } } }为什么到方波时就不得了啊?会出现失真的现象啊? |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
377 浏览 0 评论
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】(第三篇)ADC采集+PWM输出
536 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十五章 人脸识别实验
540 浏览 0 评论
950 浏览 0 评论
如何用OpenCV的相机捕捉视频进行人脸检测--基于米尔NXP i.MX93开发板
1403 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11760 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 07:20 , Processed in 0.544333 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号