单片机开发之SDCCPYTHON.doc_第1页
单片机开发之SDCCPYTHON.doc_第2页
单片机开发之SDCCPYTHON.doc_第3页
单片机开发之SDCCPYTHON.doc_第4页
单片机开发之SDCCPYTHON.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1, 安装SDCC和PYTHON:在百度上搜索SDCC//projects/sdcc/files/下载并安装该软件先安装python-2.6.4.msi (Python软件)在安装pyserial-2.5-rc2.win32.exe(串口插件)输入下面命令完成简单的串口此操作。import seriala=serial.Serial()a.port=0 #0对应串口COM1a.baudrate=9600a.open()a.write(abcd) #发送字符到串口注意:最新版本的PYTHON不支持串口控件。使用SDCC编辑单片机程序:使用记事本编辑批处理文件,用于快速编译单片机程序。使用notepad+编辑单片机程序a.c#include 8052.h/SFR FOR STC12C5A60S2_sbit _at (0x80) P0_0 ;_sbit _at (0x81) P0_1 ;_sbit _at (0x82) P0_2 ;_sbit _at (0x83) P0_3 ;_sbit _at (0x84) P0_4 ;_sbit _at (0x85) P0_5 ;_sbit _at (0x86) P0_6 ;_sbit _at (0x87) P0_7 ;_sbit _at (0x90) P1_0 ;_sbit _at (0x91) P1_1 ;_sbit _at (0x92) P1_2 ;_sbit _at (0x93) P1_3 ;_sbit _at (0x94) P1_4 ;_sbit _at (0x95) P1_5 ;_sbit _at (0x96) P1_6 ;_sbit _at (0x97) P1_7 ;_sbit _at (0xA0) P2_0 ;_sbit _at (0xA1) P2_1 ;_sbit _at (0xA2) P2_2 ;_sbit _at (0xA3) P2_3 ;_sbit _at (0xA4) P2_4 ;_sbit _at (0xA5) P2_5 ;_sbit _at (0xA6) P2_6 ;_sbit _at (0xA7) P2_7 ;_sfr _at(0xf9) CH;_sfr _at(0xfa) CCAP0H;_sfr _at(0xfb) CCAP1H;_sfr _at(0xf2) PCA_PWM0;_sfr _at(0xf3) PCA_PWM1;_sfr _at(0xe9) CL;_sfr _at(0xea) CCAP0L;_sfr _at(0xeb) CCAP1L;_sfr _at(0xc8) P5;_sfr _at(0xc9) P5M1;_sfr _at(0xca) P5M0;_sfr _at(0xcd) SPSTAT;_sfr _at(0xce) SPCTL;_sfr _at(0xcf) SPDAT;_sfr _at(0xc1) WDT_CONR;_sfr _at(0xc2) IAP_DATA;_sfr _at(0xc3) IAP_ADDRH;_sfr _at(0xc4) IAP_ADDRL;_sfr _at(0xc5) IAP_CMD;_sfr _at(0xc6) IAP_TRIG;_sfr _at(0xc7) IAP_CONTR;_sfr _at(0xb9) SADEN;_sfr _at(0xbb) P4SW;_sfr _at(0xbc) ADC_CONTR;_sfr _at(0xbd) ADC_RES;_sfr _at(0xbe) ADC_RESL;_sfr _at(0xb1) P3M1;_sfr _at(0xb2) P3M0;_sfr _at(0xb3) P4M1;_sfr _at(0xb4) P4M0;_sfr _at(0xb5) IP2;_sfr _at(0xb6) IP2H;_sfr _at(0xa9) SADDR;_sfr _at(0xaf) IE2;_sfr _at(0xa1) BUS_SPEED;_sfr _at(0xa2) AUXR1;_sfr _at(0x9a) S2CON;_sfr _at(0x9b) S2BUF;_sfr _at(0x9c) BRT;_sfr _at(0x9d) P1ASF;_sfr _at(0x91) P1M1;_sfr _at(0x92) P1M0;_sfr _at(0x93) P0M1;_sfr _at(0x94) P0M0;_sfr _at(0x95) P2M1;_sfr _at(0x96) P2M0;_sfr _at(0x97) CLK_DIV;_sfr _at(0x8e) AUXR;_sfr _at(0x8f) WAKE_CLKO;void UartInit(void);void send(void);unsigned char rdata;unsigned char sdata;_bit flag1;_bit flaga;_bit flagb;_bit flagc;_bit flagr;_bit flags;void main(void)flaga=0;flagb=0;flagc=0;flagr=0;flags=0;flag1=0;UartInit();while(1)if(flag1=1)flag1=0;if(rdata=0x61)flaga=1;flagb=0;flagc=0;if(rdata=0x62)flaga=0;flagb=1;flagc=0;if(rdata=0x63)flaga=0;flagb=0;flagc=1;if(rdata=0x72)flagr=1;flags=0;if(rdata=0x73)flagr=0;flags=1;if(flaga=1)if(flagr=1)if(rdata=0x31)P0_0=0;if(rdata=0x32)P0_1=0;if(rdata=0x33)P0_2=0;if(rdata=0x34)P0_3=0;if(rdata=0x35)P0_4=0;if(rdata=0x36)P0_5=0;if(rdata=0x37)P0_6=0;if(rdata=0x38)P0_7=0;if(flags=1)if(rdata=0x31)P0_0=1;if(rdata=0x32)P0_1=1;if(rdata=0x33)P0_2=1;if(rdata=0x34)P0_3=1;if(rdata=0x35)P0_4=1;if(rdata=0x36)P0_5=1;if(rdata=0x37)P0_6=1;if(rdata=0x38)P0_7=1;if(flagb=1)if(flagr=1)if(rdata=0x31)P1_0=0;if(rdata=0x32)P1_1=0;if(rdata=0x33)P1_2=0;if(rdata=0x34)P1_3=0;if(rdata=0x35)P1_4=0;if(rdata=0x36)P1_5=0;if(rdata=0x37)P1_6=0;if(rdata=0x38)P1_7=0;if(flags=1)if(rdata=0x31)P1_0=1;if(rdata=0x32)P1_1=1;if(rdata=0x33)P1_2=1;if(rdata=0x34)P1_3=1;if(rdata=0x35)P1_4=1;if(rdata=0x36)P1_5=1;if(rdata=0x37)P1_6=1;if(rdata=0x38)P1_7=1;if(flagc=1)if(flagr=1)if(rdata=0x31)P2_0=0;if(rdata=0x32)P2_1=0;if(rdata=0x33)P2_2=0;if(rdata=0x34)P2_3=0;if(rdata=0x35)P2_4=0;if(rdata=0x36)P2_5=0;if(rdata=0x37)P2_6=0;if(rdata=0x38)P2_7=0;if(flags=1)if(rdata=0x31)P2_0=1;if(rdata=0x32)P2_1=1;if(rdata=0x33)P2_2=1;if(rdata=0x34)P2_3=1;if(rdata=0x35)P2_4=1;if(rdata=0x36)P2_5=1;if(rdata=0x37)P2_6=1;if(rdata=0x38)P2_7=1;void UartInit1(void)/9600bps18.432MHz 使用T1作为波特率发生器 PCON &= 0x7f;/波特率不倍速SCON = 0x50;/8位数据,可变波特率TMOD &= 0x0f;/清除定时器1模式位TMOD |= 0x20;/设定定时器1为8位自动重装方式TL1 = 0xFB;/设定定时初值TH1 = 0xFB;/设定定时器重装值ET1 = 0;/禁止定时器1中断TR1 = 1;/启动定时器1ES=1;EA=1;void UartInit(void)/9600bps18.432MHz 使用STC12C5A60S2独立波特率发生器PCON &= 0x7f;/波特率不倍速SCON = 0x50;/8位数据,可变波特率BRT = 0xFB;/设定独立波特率发生器重装值AUXR &= 0xfb;/独立波特率发生器时钟为Fosc/12,即12TAUXR |= 0x01;/串口1选择独立波特率发生器为波特率发生器AUXR |= 0x10;/启动独立波特率发生器ES=1;EA=1;void it_uart(void) _interrupt(4)_using(1)while (!RI);rdata=SB

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论