用phthon生成C语言文件

上传人:夏** 文档编号:507242872 上传时间:2023-09-02 格式:DOCX 页数:3 大小:213.03KB
返回 下载 相关 举报
用phthon生成C语言文件_第1页
第1页 / 共3页
用phthon生成C语言文件_第2页
第2页 / 共3页
用phthon生成C语言文件_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《用phthon生成C语言文件》由会员分享,可在线阅读,更多相关《用phthon生成C语言文件(3页珍藏版)》请在金锄头文库上搜索。

1、用phthon生成C语言文件这是我个人的第一篇关于技术的文章,我是一只菜鸟,做硬件的,请大家多多关照啊!我的新浪微博Jet_Xie1. 起因:前些天,我在写PIC16LF1907的LCD驱动,其中一段代码如下:union uchar data; struct unsigned SEG0COM0 : 1; unsigned SEG0COM1 : 1; unsigned SEG0COM2 : 1; unsigned SEG0COM3 : 1; bits; LCDDATA0 0x140;union uchar data; struct unsigned SEG1COM0 : 1; unsigned

2、SEG1COM1 : 1; unsigned SEG1COM2 : 1; unsigned SEG1COM3 : 1; bits; LCDDATA0 0x141;(此处省略N行)union uchar data; struct unsigned SEG23COM0 : 1; unsigned SEG23COM1 : 1; unsigned SEG23COM2 : 1; unsigned SEG23COM3 : 1; bits; LCDDATA23 0x157;这代码让老板看见了,他说,这样有规律的代码应该要用代码去生成!这是怎么一回事?他让我先把python环境安装了。2. python环境搭

3、建:这步简单,网上也有好多教材,只要在python官网找到相应平台下的python安装就可以了我安装的是Python 2.7.2 Windows Installer(Windows binary - does not include source)完了设一下环境变量就可以,如图:不过其实对于我这个应用,不用配置也是没关系的啦!然后随便写段代码,运行成功感叹一下用它写代码多么方便啊!_ (我是刚刚接触python的,大家见笑)3. 用phthon生成C语言文件:直接上代码:tmpl = volatile union uchar data; struct unsigned SEG%(idx)dCO

4、M0 : 1; unsigned SEG%(idx)dCOM1 : 1; unsigned SEG%(idx)dCOM2 : 1; unsigned SEG%(idx)dCOM3 : 1; bits; LCDDATA%(idx)d 0x%(addr)x;with open(lcd_def.h, w) as outfile: for i in range(24): idx = i addr = 0x140+i outfile.write( tmpl % idx: idx, addr: addr )就是在一个lcd_def.h文件里循环写入那类似的代码。保存后运行一下,文章最前面的代码就自动生成了!

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 机械/制造/汽车 > 汽车技术

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号