完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我是PIC汇编语言编程新手。我一直在学习如何将LCD与PIC接口。我已经学会如何将输出发送到LCD,一次一个字符。我现在试图写一个代码,其中工作寄存器在一个循环中通过使用ADDLW添加一个数字来更新。我希望LCD能实时显示这种情况。也就是说,每一次,WRGG的值上升,它应该显示在LCD上。我似乎不能让它起作用。这是我的全部代码。
以上来自于百度翻译 以下为原文 hi, I am new to PIC assembly language programming. I have been learning how to interface the LCD with the PIC. I have already learned how to send output to the LCD, one character at a time. I am now trying to write a code where the working register is updated in a loop by adding a number to it using addlw. I want the LCD to show this happening in real time. I.e. every time, the value of the wreg goes up, it should show on the LCD. I can't seem to get this to work. Here is my full code. list p=16f690 #include "p16f690.inc" ;CONFIG ;__config 0xFFF __CONFIG _FOSC_INTRCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON ;errorlevel -302 cblock 20H ;declaration of variables count count1 R1 R2 R3 R4 R5 endc LCD_DATA equ PORTC ;set LCD pins on PORTC LCD_CONTROL equ PORTB ;LCD control pins on PORTB #define RS RB6 ;define RS pin of LCD #define EN RB7 ;define EN pin of LCD org 0x00 goto SETUP SETUP BSF STATUS, RP0 ;SWITCH TO BANK 1 CLRF PORTC ;SET PORTC AS OUTPUT CLRF PORTB ;SET PORTB AS OUTPUT BCF STATUS, RP0 ;BACK TO BANK 0 LCD_CONFIGURE ;CONFIGURE LCD SETTINGS CALL LCD_DELAY MOVLW 0x30 CALL SET_COMMAND MOVLW 0x38 ;INITIALIZE LCD 2 LINES CALL SET_COMMAND MOVLW 0x01 ;CLEAR DISPLAY CALL SET_COMMAND MOVLW 0x80 ;CURSOR ON BEGINNING OF FIRST LINE CALL SET_COMMAND MOVLW 0x0C ;DISPLAY ON CURSOR OFF CALL SET_COMMAND GOTO ADDTO_WREG ADDTO_WREG CLRW ;clear working register LOOP ADDLW D'2' ; add number 2 to the working register CALL WRITE_DATA goto LOOP ;jump back to loop SET_COMMAND MOVWF LCD_DATA ;MOVE CONTENTS OF WREG TO LCD DATA PINS BCF LCD_CONTROL, RS ;SET RS TO RECEIVE COMMANDS BSF LCD_CONTROL, EN NOP BCF LCD_CONTROL, EN ;SEND HIGH-LOW PULSE TO EN TO ALLOW LCD TO LATCH IN DATA PRESENT AT PINS CALL LCD_DELAY ;HOLD RETURN WRITE_DATA MOVWF LCD_DATA ;MOVE CONTENTS OF WREG TO LCD DATA PINS BSF LCD_CONTROL, RS ;SET RS TO RECEIVE DATA BSF LCD_CONTROL, EN NOP BCF LCD_CONTROL, EN ;SEND HIGH-LOW PULSE TO EN TO ALLOW LCD TO LATCH IN DATA PRESENT AT PINS CALL CLEAR ;CLEAR DISPLAY CALL LCD_DELAY ;HOLD RETURN CLEAR MOVLW 0x01 ;CLEAR DISPLAY SCREEN CALL SET_COMMAND MOVLW 0x80 CALL SET_COMMAND ;FORCE CURSOR BACK TO BEGINNING OF LINE DELAY MOVLW D'100' MOVWF R4 LOOP1 DECFSZ R4, 1 GOTO LOOP1 RETURN LCD_DELAY MOVLW D'125' MOVWF R1 L2 MOVLW D'100' MOVWF R2 L1 MOVLW D'8' MOVWF R3 L NOP NOP DECFSZ R3, 1 GOTO L DECFSZ R2, 1 GOTO L1 DECFSZ R1, 1 GOTO L2 RETURN END |
|
相关推荐
5个回答
|
|
你不能使用W寄存器作为一个变量,所有其他的都使用W寄存器,立即损坏你的值。例如,在“清除”子程序中的第一个指令是“MOVLW 0x01”,而“LCDL延迟”函数中的第一个指令是“MOVLW D’125”,你是否假设每个?代码块有自己的W寄存器的副本吗?它不存在,只有一个,使用另一个变量。您已经在CUBL中声明了七个。
以上来自于百度翻译 以下为原文 You cannot use the W register as a variable like that. Everything else uses the W register as well, instantly corrupting your value. e.g. the first instruction in the "CLEAR" subroutine is "MOVLW 0x01 ", and the first instruction in the "LCD_DELAY" function is "MOVLW D'125'" Are you assuming that each block of code has its own copy of the W register? It doesn't, there is only one. Use another variable. You already have seven declared in your CBLOCK. |
|
|
|
HI,将二进制整数值解码为十进制数字是一个相当复杂的过程,即使是一个8位无符号值,它的值可能在0到255之间。当将字符发送到显示器时,每个十进制数字或字母都是一个单独的显示字符。0和9之间的数字是字符。当将字符发送到LCD时,值为0x30到0x39。在每一个数字位置显示一个单独的变量可能比较容易。迈西尔
以上来自于百度翻译 以下为原文 Hi, Decoding a binary integer value into decimal digits is a quite complicated procedure, even for a 8 bit unsigned value, which may have values between 0 and 255. When sending characters to the display, each decimal digit, or letter is a separate display character. Digits between 0 and 9 are character values 0x30 to 0x39 when sending characters to LCD. It may be easier to keep a separate variable in the program for each digit position to be displayed. Mysil |
|
|
|
嗨,我意识到了。LCD工作良好,当我通过个别字母或数字十六进制形式。我试图推进这一点,因为我最终将需要创建一个项目,其中模拟数据收集和实时更新的LCD。我不知道如何接近代码,以使ADDWF指令的输出作为一个单独的变量存储在每个数字位置之前,我可以把它输出到LCD。请帮助
以上来自于百度翻译 以下为原文 Hi, I am realizing that. The LCD works well when I push through individual letters or digits in hex form. I am trying to advance this because I will eventually be required to create a project where analog data is collected and updated real time on the LCD. I do not know how to approach the code, to make the output of my addwf instruction, be stored as a separate variable for each digit position before I can output it to the LCD. Please help |
|
|
|
我根据您的反馈更新了代码,并简化了它,在AdWWF指令之后只打印一个值。代码仍然不能正常工作。当我试图模仿Proteus时,我会发现以下错误。下面是新代码
以上来自于百度翻译 以下为原文 I updated the code according to your feedback and simplified it to just print one value after an addwf instruction. The code is still not working. I get the following errors on proteus when I try to simulate it. Here is the new code list p=16f690 #include "p16f690.inc" ;CONFIG ;__config 0xFFF __CONFIG _FOSC_INTRCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON ;errorlevel -302 cblock 20H ;declaration of variables COUNT COUNT1 R1 R2 R3 R4 endc LCD_DATA equ PORTC ;set LCD pins on PORTC LCD_CONTROL equ PORTB ;LCD control pins on PORTB #define RS RB6 ;define RS pin of LCD #define EN RB7 ;define EN pin of LCD org 0x00 goto SETUP SETUP BSF STATUS, RP0 ;SWITCH TO BANK 1 CLRF PORTC ;SET PORTC AS OUTPUT CLRF PORTB ;SET PORTB AS OUTPUT BCF STATUS, RP0 ;BACK TO BANK 0 LCD_CONFIGURE ;CONFIGURE LCD SETTINGS CALL LCD_DELAY MOVLW 0x30 CALL SET_COMMAND MOVLW 0x38 ;INITIALIZE LCD 2 LINES CALL SET_COMMAND MOVLW 0x01 ;CLEAR DISPLAY CALL SET_COMMAND MOVLW 0x80 ;CURSOR ON BEGINNING OF FIRST LINE CALL SET_COMMAND MOVLW 0x0E ;DISPLAY ON CURSOR BLINKING CALL SET_COMMAND GOTO ADDTO_REG ADDTO_REG CLRF COUNT ;clear register MOVLW 0x02 ADDWF COUNT, F ;add value of working reg to count, store result in count MOVF COUNT, W ;move value of count to wreg CALL WRITE_DATA SET_COMMAND MOVWF LCD_DATA ;MOVE CONTENTS OF WREG TO LCD DATA PINS BCF LCD_CONTROL, RS ;SET RS TO RECEIVE COMMANDS BSF LCD_CONTROL, EN NOP BCF LCD_CONTROL, EN ;SEND HIGH-LOW PULSE TO EN TO ALLOW LCD TO LATCH IN DATA PRESENT AT PINS CALL LCD_DELAY ;HOLD RETURN WRITE_DATA MOVWF LCD_DATA ;MOVE CONTENTS OF WREG TO LCD DATA PINS BSF LCD_CONTROL, RS ;SET RS TO RECEIVE DATA BSF LCD_CONTROL, EN NOP BCF LCD_CONTROL, EN ;SEND HIGH-LOW PULSE TO EN TO ALLOW LCD TO LATCH IN DATA PRESENT AT PINS CALL LCD_DELAY ;HOLD RETURN DELAY MOVLW D'1000' MOVWF R4 LOOP1 DECFSZ R4, 1 GOTO LOOP1 RETURN LCD_DELAY MOVLW D'125' MOVWF R1 L2 MOVLW D'100' MOVWF R2 L1 MOVLW D'8' MOVWF R3 L NOP NOP DECFSZ R3, 1 GOTO L DECFSZ R2, 1 GOTO L1 DECFSZ R1, 1 GOTO L2 RETURN END Attached Image(s) |
|
|
|
这里:“Goto AdtoTyRg”应该是在该代码之后,而不是在它之前。I.这就是为什么您得到“堆栈下溢”消息,因为您正直接运行到一个只需调用的子例程中。
以上来自于百度翻译 以下为原文 Here: GOTO ADDTO_REG ADDTO_REG CLRF COUNT ;clear register MOVLW 0x02 ADDWF COUNT, F ;add value of working reg to count, store result in count MOVF COUNT, W ;move value of count to wreg CALL WRITE_DATA The "GOTO ADDTO_REG " should have been AFTER that code, not before it. i.e ADDTO_REG CLRF COUNT ;clear register MOVLW 0x02 ADDWF COUNT, F ;add value of working reg to count, store result in count MOVF COUNT, W ;move value of count to wreg CALL WRITE_DATA GOTO ADDTO_REG That is why you are getting the "stack underflow" message, because you are running straight into a subroutine you should only be calling. |
|
|
|
只有小组成员才能发言,加入小组>>
5212 浏览 9 评论
2019 浏览 8 评论
1944 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3192 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2246 浏览 5 评论
760浏览 1评论
647浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
567浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
659浏览 0评论
557浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-11 22:51 , Processed in 1.216482 second(s), Total 57, Slave 49 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号