VB6.0小程序控制单片机P1口8位LED

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

VB6.0小程序控制单片机P1口8位LED单片机程序:BZBITP3.3DISPEQUP1INBUFFEQU30HINBUFF1EQU31HINBUFF2EQU32HINBUFF3EQU33HINBUFF4EQU34HINBUFF5EQU35HINBUFF6EQU36HINBUFF7EQU37HINBUFF8EQU38HINDATA_AEQU39HINDATA_BEQU40HINDATA_CEQU41HINDATA_DEQU42HOUTBUFFEQU43HOUTDATA1EQU44HOUTDATA2EQU45HOUTDATA3EQU46HOUTDATA4EQU47HOUTDATA5EQU48HOUTDATA6EQU49HOUTDATA7EQU4AHOUTDATA8EQU4BHOUTDATA_AEQU4CHOUTDATA_BEQU4DHOUTDATA_CEQU4EHOUTDATA_DEQU4FHS_AMOUNTEQU50HR_AMOUNTEQU51HR_COUNTEQU52HR_COUNTbEQU53HR_COUNTsEQU54HR_COUNTgEQU55HMYADDEQU56HLEDEQU57HDATAAEQU20HDATABEQU21HDATACEQU22HDATADEQU23HLEDDATAEQU24HDEL_TIME1EQU25HDEL_TIME2EQU26HLED_STYLEEQU27HORG0000HLJMPSTARTORG000BHLJMPTIMER0ORG0023HLJMPRI_TIORG0100HSTART:MOVSP,#60HMOVSCON,#0D0H;设置成串口工作方式3MOVTMOD,#21H;波特率发生器T1工作在模式2MOVPCON,#80H;波特率翻倍为4800*2=9600bpsMOVTH0,#3CHMOVTL0,#0B0HMOVTH1,#0FAH;预置初值(按照波特率4800bps预置初值)MOVTL1,#0FAH;预置初值(按照波特率4800bps预置初值)MOVIE,#92HSETBPS;串口中断优先SETBTR1;启动定时器T1MOVMYADD,#01HMOVR_COUNT,#0MOVR_AMOUNT,#8MOVR0,#INBUFF1MOVR_COUNTb,#30HMOVR_COUNTs,#30HMOVR_COUNTg,#30HMOVINBUFF1,#94;MOVINBUFF2,#94;MOVINBUFF3,#94;MOVINBUFF4,#94;MOVLED,#00HMOVDEL_TIME1,#2MOVDEL_TIME2,#2MOVLED_STYLE,#0LCALLBELLMOVLEDDATA,#0FFH;SETBLED;========初始化显示器MOVDISP,#0FFHLJMP$;=======================TIMER0:PUSHPSWPUSHACCMOVTH0,#3CHMOVTL0,#0B0HDJNZDEL_TIME1,OUT_T0MOVDEL_TIME1,DEL_TIME2T0_TURN:MOVA,#1CJNEA,LED_STYLE,T0_SUNDRYMOVA,DISPRLAMOVDISP,AJMPOUT_T0T0_SUNDRY:MOVA,#2CJNEA,LED_STYLE,T0_FLASHMOVA,DISPCPLAMOVDISP,AJMPOUT_T0T0_FLASH:MOVA,#3CJNEA,LED_STYLE,OUT_T0MOVA,DISPCPLAMOVDISP,AOUT_T0:POPPSWPOPACCRETI;========发送子程序==========SEND_BYTE:MOVS_AMOUNT,#8MOVR1,#OUTDATA1SEND_BIT:MOVA,@R1MOVSBUF,AJNBTI,$CLRTIDJNZS_AMOUNT,SENDNEXTRETSENDNEXT:INCR1LJMPSEND_BIT;=======指令比较==============ORDER_COMP:;=======收到连接信号MOVA,#4CH;LCJNEA,INDATA_A,OR_STARTMOVA,#5CH;\CJNEA,INDATA_B,OR_STARTMOVA,#5CH;\CJNEA,INDATA_C,OR_STARTMOVA,#5CH;\CJNEA,INDATA_D,OR_START;——-发送连接成功信号MOVOUTDATA_A,#52H;RMOVOUTDATA_B,#4CH;L MOVOUTDATA_C,#5CH;\MOVOUTDATA_D,#5CH;\LCALLPACKRET;=======收到开始信号OR_START:MOVA,#53H;SCJNEA,INDATA_A,OR_OFFLINKMOVA,#5CH;\CJNEA,INDATA_B,OR_OFFLINKMOVA,#5CH;\CJNEA,INDATA_C,OR_OFFLINKMOVA,#5CH;\CJNEA,INDATA_D,OR_OFFLINK;——-发送系统就绪信号MOVOUTDATA_A,#52H;RMOVOUTDATA_B,#52H;RMOVOUTDATA_C,DISP;#5CH;\MOVOUTDATA_D,#5CH;\LCALLPACKRET;=======收到脱机信号OR_OFFLINK:MOVA,#4FH;OCJNEA,INDATA_A,OR_INFORMOVA,#5CH;\CJNEA,INDATA_B,OR_INFORMOVA,#5CH;\CJNEA,INDATA_C,OR_INFORMOVA,#5CH;\CJNEA,INDATA_D,OR_INFOR;——-发送脱机成功信号MOVOUTDATA_A,#52H;RMOVOUTDATA_B,#53H;SMOVOUTDATA_C,#5CH;\MOVOUTDATA_D,#5CH;\LCALLPACKRET;=======收到命令信息OR_INFOR:MOVA,#57H;WCJNEA,INDATA_A,OR_ALLOW;——-发送校验信息MOVOUTDATA_A,#49H;IMOVOUTDATA_B,INDATA_BMOVOUTDATA_C,INDATA_CMOVOUTDATA_D,INDATA_D;——-保存信息MOVDATAA,INDATA_AMOVDATAB,INDATA_BMOVDATAC,INDATA_CMOVDATAD,INDATA_DLCALLPACKRET;=======收到允许执行信号OR_ALLOW:MOVA,#41H;ACJNEA,INDATA_A,OR_CLICKMOVA,#41H;ACJNEA,INDATA_B,OR_CLICKMOVA,#41H;ACJNEA,INDATA_C,OR_CLICKMOVA,#41H;ACJNEA,INDATA_D,OR_CLICK;———————————MOVA,DATACANLA,#0FHSWAPAANLDATAD,#0FHADDA,DATADMOVLEDDATA,A;2位数据合并成1位ON_LED:MOVA,#00H;点亮LEDCJNEA,DATAB,OFF_LEDCLRTR0MOVA,LEDDATAANLA,DISPMOVDISP,A;低电平点亮LEDLJMPOUT_LEDOFF_LED:MOVA,#01HCJNEA,DATAB,FLASH_LEDCLRTR0MOVA,LEDDATAORLA,DISPMOVDISP,A;低电平点亮LEDLJMPOUT_LEDOR_CLICK:LJMPERRORFLASH_LED:MOVA,#46H;FCJNEA,DATAB,SUNDRY_LEDMOVDISP,#00HMOVDEL_TIME1,DATACMOVDEL_TIME2,DATACSETBTR0MOVDISP,#00HMOVLED_STYLE,#3LJMPOUT_LEDSUNDRY_LED:MOVA,#53H ;SCJNEA,DATAB,TURN_LEDMOVDISP,#01010101BMOVDEL_TIME1,DATACMOVDEL_TIME2,DATACSETBTR0MOVDISP,#01010101BMOVLED_STYLE,#2LJMPOUT_LEDTURN_LED:MOVA,#54H;TCJNEA,DATAB,PAUSE_LEDMOVDISP,#0FEHMOVDEL_TIME1,DATACMOVDEL_TIME2,DATACSETBTR0MOVDISP,#0FEHMOVLED_STYLE,#1LJMPOUT_LEDPAUSE_LED:MOVA,#50H;PCJNEA,DATAB,OUT_LED;MOVDEL_TIME,DATACCLRTR0OUT_LED:NOPRET;=======收到XX信号;=======收到XX信号;=======打包8字节数据后发送==========PACK:MOVOUTDATA1,#01H;SOHMOVOUTDATA2,MYADD;站号MOVOUTDATA3,#06H;ACKMOVOUTDATA4,OUTDATA_A;接收的数据MOVOUTDATA5,OUTDATA_B;MOVOUTDATA6,OUTDATA_C;MOVOUTDATA7,OUTDATA_D;MOVOUTDATA8,#03H;ETXLCALLSEND_BYTERETERROR:;=======发送无效信息MOVOUTDATA1,#01H;SOHMOVOUTDATA2,MYADD;站号MOVOUTDATA3,#15H;NAKMOVOUTDATA4,INDATA_A;?数据MOVOUTDATA5,INDATA_B;?MOVOUTDATA6,INDATA_C;?MOVOUTDATA7,INDATA_D;?MOVOUTDATA8,#03H;ETXLCALLSEND_BYTELJMPENDT;=====串口中断处理子程序===========RI_TI:PUSHPSW;PUSHACCJBCRI,RECEIVE;;;;;CLRRICLRTI;;;;LJMPENDTRECEIVE:MOVA,SBUFMOV@R0,ADJNZR_AMOUNT,NEXTIN;8字节接收完毕?MOVR_AMOUNT,#8MOVR0,#INBUFF1;=======比较接收到的8字节数据MOVA,INBUFF1CJNEA,#01H,ERROR;SOHMOVA,INBUFF2CJNEA,MYADD,ERROR;站号MOVA,INBUFF3CJNEA,#05H,ERROR;ENQMOVA,INBUFF8CJNEA,#03H,ERROR;ETXMOVINDATA_A,INBUFF4MOVINDATA_B,INBUFF5MOVINDATA_C,INBUFF6MOVINDATA_D,INBUFF7LCALLORDER_COMP;指令比较LCALLBELLENDT:POPACCPOPPSWRETINEXTIN:CJNER0,#INBUFF1,RI_NEXT;收到第一字?MOVA,@R0;——-收到检测信号CJNEA,#43H,RI_NEXT;收到的第一字节是C?;——-发送回应8字节数据MOVOUTDATA_A,#46H;FMOVOUTDATA_B,DISPMOVOUTDATA_C,#5CH;\MOVOUTDATA_D,#5CH;\LCALLPACKLJMPENDTRI_NEXT:INCR0;=======接收到一字节后发送同步空转标志MOVA,#16HMOVSBUF,A;每收到8字节就发送7个同步空转LJMPENDTDISPLAY:;—–接收次数RET;=================================BELL:CLRBZLCALLDEL_10MSSETBBZRET;======10毫秒延时子程序DEL_10MS:MOVR6,#2D10MS:MOVR7,#50DJNZR7,$DJNZR

1 / 37
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功