NEXTION - PIC16F877A

Jtomas

New Member
Hello everyone,
I'm glad I found this site, I would appreciate if someone has made a connection between a Nextion screen and a PIC, using PIC SIMULATOR IDE, I'm stuck and I'm not able to capture the codes of the buttons that I've entered on the NEXTION screen from the PIC. I'm able to send data from the PIC to the Nextion but not the other way around. I'd appreciate some help.
Thank you very much.
 
There are several Nextion screens, each has complexity from basic to advanced set of instructions.

Looking at the protocol, it seems a little complex to say the least. What model have you got? Have you some starter code that you have written? I am looking into TFT LCD for Oshonsoft as we speak.
 
Thank you very much for your answer. I am attaching part of the code in PIC SIMULATOR IDE and an image of the NEXTION screen where you can see the text that I want to send to the PIC using the Buttons. I am able to send text to Nextion and numeric values, but I am not able to read what Nextion is sending me. The truth is that I am quite desperate because I don't know what to do anymore. I have tried different print commands from Nextion and there is no way. I don't know if I have the PIC configured incorrectly. I am an amateur and my knowledge is not very extensive. Regards and thanks.
 

Attachments

  • Image_1.jpg
    271.8 KB · Views: 25
  • loop-cat_v5.bas
    2 KB · Views: 14
My help will be hindered by my not having that device..

When you created the design, what did you create to send when button A and button B was selected?

When you send text you are sending "t2.text =" then your text followed by the 255,255,255.. which I see is correct. When reading the output You will get a touch event (0x65) Capital A then three bytes
page, component, condition.

So you'll need to read 4 bytes
Code:
if  get i = 'A'  then
  page  = get i
  component = get i
  cond = get i
end if

if event then
if page = o then
if component = 1 then do condition ( up or down )
or something like this.

!!! Remember to grab the three 255's at the end.. or they will carry through!
 
Hello,
Thank you for answering, I think I may not have explained myself correctly, in reference to the Nextion Screen the conditions
They are as follows, I only use one page, the button identifier is not necessary to send as I have seen in some video, where the problem lies, I think it is in the declaration of the "char" variable that does not exist in Pic Simulator IDE, if It looks good, I am attaching a link that is the guide I used to develop the code, but it is written in MikroC for PIC. And from Nextion I send the character "a" through the print when pressing the Button b0 event. I am going to attach the PSI code that I created, it is the closest to the one used in the video. I would appreciate your opinion.

This is the link:
greetings
 

Attachments

  • loop-cat_v6.bas
    2.2 KB · Views: 18
Hello, I’ve been a bit absent from the forum as work has kept me busy lately.

Anyway, the "char" variable in C is equivalent to the "Byte" variable in Pic Simulator IDE. If you want to get a bit more technical, you can declare the "char" variable like this: Dim Char[1] as String. This will declare "Char" as a String type variable, and Pic Simulator will treat it as a 1-byte string (internally it uses 2 bytes, but the second one doesn't concern us). This offers both advantages and limitations.

Example:

Dim Char[1] as String
Char = "A" 'As a string
Char = Chr(65) 'As a string
Char = 65 'Not allowed as 8-bit integer.
Char(0) = 65 'Allowed as 8-bit integer, bypassing the restriction.

I'm not sure if this will help with your program, but I thought it might clarify things.
 
Last edited:
Thank you very much, I'll see if I can solve this problem. Another question I have is whether I have to activate any register, but I'm not sure. I think that using the hardware UART is not necessary. Please, if I have made any mistake, I would appreciate it if you correct me. Thank you very much.
Greetings from - Berga - Catalonia.
 
Just out of curiosity, double quotes will normally (C) result in a zero terminated string (two bytes long). Single quotes results in a one byte character.

Is this the same in Oshonsoft?

Mike.
 
The language does not allow as much freedom as in C but the effect is the same.

The only way to use them is if the variable was declared as String and it means empty string or 0, that is, it assigns a zero value.
Continuing with the previous example:
Char = "" 'Empty string or assignment of 0 to the first character of the string.
which is the same as Char(0) = 0
And since in C, the programmer has to be careful not to exceed the length of the string.

The ASCII symbol ' is not allowed.
 
Last edited:
You should configure the fuses for the 877A at the beginning of the program, but the default settings usually work.
And here is the link to a small thread that refers to the usart configuration:


I always use Usart for hardware.
 
Last edited:
Thanks everyone for replying, in reply to a colleague single quotes don't work with PIC SIMULATOR IDE, at least that's how I understand it. Well I will investigate to see what I am doing wrong, in principle I only have an error in reading NEXTION to PIC, from PIC to NEXTION I have no problems. I don't know if it could be a Delays problem, but with all the examples I've seen there are no delays when reading the PIC. Well if someone can provide a possible cause it would be fantastic.
Greetings to all.
 
As a comment, the Program works well with PROTEUS and a connection with Virtual ports with the NEXTION Screen.
Too bad I haven't found anyone who works with PIC SIMULATOR IDE and NEXTION, I find this software very good for programming and simulating microcontrollers,
 
I find it strange that it’s not working if you're using the IDE functions. It’s common to have issues with Rx at first because it's more sensitive. If more data enters than what’s being read, the USART module can lock up. In any case, if you want to use functions for a RingBuffer that have been thoroughly tested (I’ve been using them for over 10 years), I can send you the link. These functions handle everything—USART lock detection and other issues. They provide a complete solution. The downside is that they use interrupts, but once you integrate them into your code, they take care of everything. In any case, I’ll try to find time to review your program and see if I can spot the issue.
 
I don't see any major issues; the fuse configuration should be this: #define CONFIG = 0x3F71, but I believe the default configuration you have should also work.

One detail that might work in simulators but cause problems in real life is that you haven't defined RC7 (RX) as an input (TRISC.7 = 1). I believe the programmer is responsible for configuring this pin, and if I remember correctly, the IDE doesn’t set it as an input when using the USART module. Try these small changes, and if it still doesn’t work, I’ll check it in real hardware. I have a couple of boards based on the 877A with RS232, and I’ll try to load a basic communication program.

The last time I worked with the 877A using Pic Simulator or Compiler was 19 years ago, so for anyone curious, here’s a video of that:
 
Last edited:
The pins of the USART module are automatically configured by the compiler. If you've been using a version of the Pic Basic Compiler or simulator between v9.60 and earlier than v9.68, you might have noticed that the compiler functions for controlling the USART in RX mode do not work properly. These updates, released about 2 or 3 weeks ago, introduced significant improvements to the compiler but also came with this issue. Fortunately, they fixed it in less than 24 hours, which is commendable. You can now download the corrected version v9.68, which I have tested with the Pic16F877, and it works perfectly.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…