How to send & receive data with interrupt in RS232

413 views
Skip to first unread message

majid ebru

unread,
Apr 18, 2021, 3:15:19 PM4/18/21
to jallib

Hi
i have two PIC16f877A.
how can i use Interrupt for send& receive data between they??
i should use Serial_Software
------------

        ;@jallib section chipdef
-- chip setup
include 16f877a
pragma target clock 8_000_000                  -- xtal frequency
pragma target OSC   hs
pragma target WDT   disabled
pragma target LVP   disabled
enable_digital_io()
include print
include delay
intcon_gie =  true            -- Enable interrupt generally
-------------------------- Port A ---------------------------------
const bit  ADC_HIGH_rESOLUTION = low
const word ADC_rSOUrCE = 2_000
const byte ADC_NVrEF = ADC_VrEF_POS--ADC_NO_EXT_VrEF--ADC_NO_VrEF-- and one Vref pin
const byte ADC_NCHANNEL = 3                --- our 6 ADC channel
include adc
include math
adc_init()
var word ADC_Input_general_1 = 0
var word ADC_Input_general_2 = 0
var word ADC_Input_general_3 = 0
-------------------------------------------- ok, now setup serial
alias serial_sw_tx_pin is pin_C4
alias serial_sw_rx_pin is pin_C5
pin_C4_direction = output
const serial_sw_baudrate = 9600
var bit serial_sw_invert = false
include serial_software
serial_sw_init()
-------------------------- Port B ---------------------------------
alias in1 is pin_b0
pin_b0_direction = input
--------------------------------
alias in2 is pin_b1
pin_b1_direction = input
--------------------------------
alias in3 is pin_b2
pin_b2_direction = input
--------------------------------
alias in4 is pin_b3
pin_b3_direction = input
--------------------------------
alias in5 is pin_b4
pin_b4_direction = input
--------------------------------
alias in6 is pin_b5
pin_b5_direction = input
-------------------------- Port E ---------------------------------
alias SS1 is pin_e0
pin_e0_direction = output
SS1 = 0
--------------------------------
alias SS2 is pin_e1
pin_e1_direction = output
SS2 = 0
-------------------------- Port D ---------------------------------
alias Buzzer1 is pin_d1
pin_d1_direction = output
Buzzer1 = 0
--------------------------------
alias FlashLED1 is pin_d2
pin_d2_direction = output
FlashLED1 = 0
--------------------------------
alias Out_1 is pin_d3
pin_d3_direction = output
Out_1 = 0
--------------------------------
alias Out_5 is pin_d4
pin_d4_direction = output
Out_5 = 0
--------------------------------
alias Out_4 is pin_d5
pin_d5_direction = output
Out_4 = 0
--------------------------------
alias Out_3 is pin_d6
pin_d6_direction = output
Out_3 = 0
--------------------------------
alias Out_2 is pin_d7
pin_d7_direction = output
Out_2 = 0
-------------------------------------------------------------------
var word n = 0 , j = 0
-------------------------------------------------------------------
var bit bitOut1 = 0,  bitOut2 = 0
-------------------------------------------------------------------
var word press = 0
var word btnDelay = 500, btnDelay_1 = 0, btnDelay_2 = 0
var word btnDelay_3 = 0, btnDelay_4 = 0
var word buzDelay = 700, buzCount = 0 , sendByte = 0
var byte temp1 = 0
FlashLED1 = 1
--------------------------------------------------- >>> interrupt >>> ----
procedure ????? is  pragma  interrupt
    if ????? then
        block
            -- if recevive 10 => set Out_2  ??????????????
        end block
    end if
end procedure
-------------------------------------------------------------------
forever loop
-----------------------     Buzzer
    if buzDelay < buzCount then
        buzCount = 0
    end if
    if 0 < buzCount then block
      Buzzer1 = 1
        buzCount = buzCount + 1
     end block
    else
      Buzzer1 = 0
    end if
-----------------------     btn1
    if in1 == 1 then
      btnDelay_1 =    btnDelay_1 + 1
    else
      btnDelay_1 = 0
    end if
    if btnDelay < btnDelay_1 then block
        buzCount = 1
      btnDelay_1 = 0
      Out_1 = 0
      -- send Data to USART ?????????????????
     end block
    end if
--------------------------------------------------    
    if n < 8000 then block
      n = n + 1
     end block
    else block
        n = 0
        FlashLED1 = ! FlashLED1
   end block
    end if
-----------------------
end loop
-----------------------------------------------------------


please help or guide me

Oliver Seitz

unread,
Apr 18, 2021, 3:25:45 PM4/18/21
to jal...@googlegroups.com
Hi!

serial_software can't use interrupts. It is a "bit-bang" design which blocks the processor while sending data, or while waiting for incoming data.

If you're using a controller which doesn't have a usart peripheral and need to send or receive asynchronous serial signals without blocking, you would need to fire one interrupt per bit. There is no library which uses this approach, and it would also be of little use. One interrupt per bit means you can only use very low baud rates, unless your controller is a very fast one. And all the fast controllers do have usart peripherals.

Greets,
Kiste






Am Sonntag, 18. April 2021, 21:15:21 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/b69ef4ed-22dc-45d7-b710-f616ad6f3ed0n%40googlegroups.com.

majid ebru

unread,
Apr 18, 2021, 10:13:14 PM4/18/21
to jallib
Thank you very much
I just want to send/receive data with interrupt.
How can i do that?!
I should use i2c or spi
I can't find any sample about interrupt sending/receiving data in pic


Kiste در تاریخ یکشنبه ۱۸ آوریل ۲۰۲۱ ساعت ۲۳:۵۵:۴۵ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 18, 2021, 10:16:35 PM4/18/21
to jallib

Sorry
Can I use interrupt in Serial-Hardware?!
Thank you
‪majid ebru‬‏ در تاریخ دوشنبه ۱۹ آوریل ۲۰۲۱ ساعت ۶:۴۳:۱۴ (UTC+4:30) نوشت:

Oliver Seitz

unread,
Apr 19, 2021, 12:47:16 AM4/19/21
to jal...@googlegroups.com
The library that sends and receives data in background using buffers and interrupts is called

serial_hw_int_cts

There are a lot of samples, even one called 16f877_serial_hw_int_cts.jal
It should run on an 16f877A with very little changes.
Only thing is, you can't use pins C4/C5 for TX/RX, you are bound to C6/C7 as the usart is internally hard-wired to these pins.

With very recent controllers like 18f46k42, you can internally patch the TX/RX lines to any pin of ports B or C, and there's a second uart that can be patched to any pin of port B or D.

Greets,
Kiste





Am Montag, 19. April 2021, 04:38:52 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
https://groups.google.com/d/msgid/jallib/f78f32c2-569b-4560-8472-098f637c082cn%40googlegroups.com
.

vsurducan

unread,
Apr 19, 2021, 7:03:31 AM4/19/21
to jal...@googlegroups.com
Hi,
Perhaps you would look at the library serial_hw_int_cts.jal and adapt the (not very) simplified routine below at your need.
The received data is in RCREG and we assume has one byte length.

var byte your_data = 0
procedure  _serial_receive_interrupt_handler() is

   pragma interrupt

   var  byte  x
   var  bit   usart_error

   if (SERIAL_RCIF == TRUE)  then        -- UART receive interrupt
      usart_error = FALSE

      if (defined(U1CON0)== TRUE) then
         -- Newer USART type
         if U1ERRIR_FERIF | U1ERRIR_RXFOIF | U1ERRIR_RXBKIF | U1ERRIR_PERIF then
            -- reset framing and/or overflow errors
            U1ERRIR_FERIF  = FALSE
            U1ERRIR_RXFOIF = FALSE
            U1ERRIR_RXBKIF = FALSE
            U1ERRIR_PERIF  = FALSE
            U1FIFO_RXBE    = TRUE       -- clear receive bufer
            usart_error    = TRUE
         end if
      else
         -- Classic USART type
         if ((RCSTA_OERR == TRUE) | (RCSTA_FERR == TRUE)) then  -- frame/overr error
            x = RCREG                              -- flush hardware buffer
            while RCSTA_OERR == TRUE loop          -- overrun state
               RCSTA_CREN = DISABLED               -- disable UART
               RCSTA_CREN = ENABLED                -- re-enable UART
               x = RCREG                           -- \  flush hardware buffers
               x = RCREG                           -- /
            end loop                               -- until no more overrun
            usart_error = TRUE
         end if
      end if
   your_data = RCREG  -- here is your data if no communication error appears
   end if

end procedure

majid ebru

unread,
Apr 19, 2021, 9:24:50 AM4/19/21
to jallib

Thank you very much
Please guide me
 Should I use your procedure in my program?!

vasile در تاریخ دوشنبه ۱۹ آوریل ۲۰۲۱ ساعت ۱۵:۳۳:۳۱ (UTC+4:30) نوشت:

Rob CJ

unread,
Apr 19, 2021, 12:53:45 PM4/19/21
to jal...@googlegroups.com
Hi Majid,

You should include the serial library and then use it.

Have a look in the Jallib sample directory and check a sample file with the name 'serial_hw_int_cts' in it.

For example: 16f19176_serial_hw_int_cts.jal 

This sample file shows a simple use of the library.  There are many more sample files.

Kind regards,

Rob



Van: jal...@googlegroups.com <jal...@googlegroups.com> namens majid ebru <majid...@gmail.com>
Verzonden: maandag 19 april 2021 15:24
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] How to send & receive data with interrupt in RS232
 

majid ebru

unread,
Apr 19, 2021, 3:17:27 PM4/19/21
to jallib

Thank you 
But I want to use interrupt
In your suggestions,16f19176_serial_hw_int_cts.jal,there isn't any interrupt routine?!!
And I read very sample , but I can't find interrupt and interrupt routine.
In your suggestions,in the main loop , you are waiting to receive data , I don't want to use this method
Ok , I will create new project and test it and said the result

rob...@hotmail.com در تاریخ دوشنبه ۱۹ آوریل ۲۰۲۱ ساعت ۲۱:۲۳:۴۵ (UTC+4:30) نوشت:

Oliver Seitz

unread,
Apr 19, 2021, 3:25:47 PM4/19/21
to jal...@googlegroups.com
You don't have to wait for data in your loop. You can check if received data is waiting in the buffer, process it if it is waiting, or go on with your loop if no data is waiting.

Or, you can read the library and learn from it, how to use interrupts. Then you can write your program without the library.

Greets,
Kiste


Am Montag, 19. April 2021, 21:17:30 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
>> procedure  _serial_receive_interrupt_handler() is   pragma interrupt   var  byte  x   var  bit   usart_error   if (SERIAL_RCIF == TRUE)  then        -- UART receive interrupt      usart_error = FALSE      if (defined(U1CON0)== TRUE) then         -- Newer USART type         if U1ERRIR_FERIF | U1ERRIR_RXFOIF | U1ERRIR_RXBKIF | U1ERRIR_PERIF then            -- reset framing and/or overflow errors            U1ERRIR_FERIF  = FALSE            U1ERRIR_RXFOIF = FALSE            U1ERRIR_RXBKIF = FALSE            U1ERRIR_PERIF  = FALSE            U1FIFO_RXBE    = TRUE       -- clear receive bufer            usart_error    = TRUE         end if      else         -- Classic USART type         if ((RCSTA_OERR == TRUE) | (RCSTA_FERR == TRUE)) then  -- frame/overr error            x = RCREG                              -- flush hardware buffer            while RCSTA_OERR == TRUE loop          -- overrun state               RCSTA_CREN = DISABLED               -- disable UART               RCSTA_CREN = ENABLED                -- re-enable UART               x = RCREG                           -- \  flush hardware buffers               x = RCREG                           -- /            end loop                               -- until no more overrun            usart_error = TRUE         end if      end if   your_data = RCREG  -- here is your data if no communication error appears   end ifend procedure
https://groups.google.com/d/msgid/jallib/bfde65b2-b272-4a10-972a-72433dc85ef1n%40googlegroups.com
.

vsurducan

unread,
Apr 19, 2021, 11:07:45 PM4/19/21
to jal...@googlegroups.com
Majid,
take a deeper look, the interrupt receiving routine in the library is the one I've shared.
Once you include the 'serial_hw_int_cts' library in your program the interrupt is already included so you need just to read the received data from the buffer.
The difference between the library and posted routine is that the last one does not use any circular buffer which may be intimidating for a new user...
You have to understand by yourself and write a test program for communication only. After it works, integrate it in your program as you need.
Do not try to make it working in a single step.
Good luck!

majid ebru

unread,
Apr 20, 2021, 9:23:52 AM4/20/21
to jallib
hi again
can any body say me what is my wrong??


Compilation started at :4/20/2021 4:48:38 PM
jal 2.4o (compiled May  8 2011)
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  "serial_ctsinv" not defined
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  'end' expected (got 'serial_ctsinv')
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  {IF starts at C:\JALPack2\lib/serial_hw_int_cts.jal:214}
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  "serial_ctsinv" not defined
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  'end' expected (got 'serial_ctsinv')
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  {IF starts at C:\JALPack2\lib/serial_hw_int_cts.jal:212}
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  "serial_ctsinv" not defined
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  'end' expected (got 'serial_ctsinv')
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  {procedure starts at C:\JALPack2\lib/serial_hw_int_cts.jal:206}
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  "serial_ctsinv" not defined
[Error] (lib/serial_hw_int_cts.jal) [Line 224]  unexpected token: "serial_ctsinv"

Thank you
My_pro_7.zip

Oliver Seitz

unread,
Apr 20, 2021, 10:25:52 AM4/20/21
to jal...@googlegroups.com
Probably, as your compiler is ten years old, you might have old libraries, too.

Years ago, the serial_hw_int_cts library needed a cts pin. If you can't use newer libraries, define a dummy pin for that

var bit serial_ctsinv

Greets,
Kiste




Am Dienstag, 20. April 2021, 15:31:41 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/jallib/d03b52e4-da68-46ce-873a-7849b0d3b697n%40googlegroups.com
.

Rob CJ

unread,
Apr 20, 2021, 10:29:44 AM4/20/21
to jallib
Hi Majid

I find the code difficult to read and you are doing too much here. 

Some observations:
  • You include the same library more than once, you should not do that.
  • The serial interrupt routine is part of the library so you do not need it here
  • Your program uses an interrupt routine so you expect that it is called becauses there is an interrupt routine in the serial library but this is not a good practice. 
I do not know if it is your intention to do stuff in an interrupt routine otherwise I would just move it to the main loop and put the check (this is not a wait) using '  if serial_hw_read(your_data)' in your main program.

I did some cleanup of your program but since I do not understand what you are trying to achieve it might be wrong.

Kind regards,

Rob


Verzonden: dinsdag 20 april 2021 15:23

Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] How to send & receive data with interrupt in RS232
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
My_pro_7_update.zip

majid ebru

unread,
Apr 20, 2021, 11:10:11 AM4/20/21
to jallib
Thank you very very much to answer

i attache two pic program

i read your update

rob...@hotmail.com در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۱۸:۵۹:۴۴ (UTC+4:30) نوشت:
PIC2PIC.zip

majid ebru

unread,
Apr 20, 2021, 11:12:56 AM4/20/21
to jallib
when i use your program , i have some Error
-----------------------
Compilation started at :4/20/2021 6:41:55 PM

jal 2.4o (compiled May  8 2011)
[Error] (lib/serial_hw_int_cts.jal) [Line 357]  "serial_overflow_discard" not defined
[Error] (lib/serial_hw_int_cts.jal) [Line 357]  ')' expected (got 'serial_overflow_discard')
[Warning] (lib/serial_hw_int_cts.jal) [Line 357]  boolean expression expected
[Error] (lib/serial_hw_int_cts.jal) [Line 357]  'then' expected (got 'serial_overflow_discard')
[Warning] (lib/serial_hw_int_cts.jal) [Line 357]  boolean expression expected
Compiler CommandLine:  C:\JALPack2\compiler\jalv2.exe "G:\Project\PCB\Temp\Temp_JAL_2\Temp_A_1\A7_USART\A7_1.jal" -s "C:\JALPack2\lib" -no-variable-reuse  

Errors :3       Warnings :1

‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۱۹:۴۰:۱۱ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 20, 2021, 11:22:10 AM4/20/21
to jallib
20210420_194852~01.jpg
sorry ,i can't edit my post so i should send new post.


i just want send and receive data between two PIC
‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۱۹:۴۲:۵۶ (UTC+4:30) نوشت:

Rob CJ

unread,
Apr 20, 2021, 11:22:13 AM4/20/21
to jallib
Hi Majid,

You are using a very old compiler (as mentioned by Kiste) and also old libraries. Please go to the JAL download site and download the latest release 1.6.0.

Both programs compile without any problems with this release (I just tested it).

Kind regards,

Rob


Verzonden: dinsdag 20 april 2021 17:12

Rob CJ

unread,
Apr 20, 2021, 11:24:24 AM4/20/21
to jal...@googlegroups.com
Hi Majid,

See my previous answer. Update your JAL version and your programs compile without any problems.

Kind regards,

Rob


Verzonden: dinsdag 20 april 2021 17:22

majid ebru

unread,
Apr 20, 2021, 11:24:45 AM4/20/21
to jallib
I download jallib from github
I download jallib   JALPack 2.4.o 0 0.9.0.9 from just another language site

Where should I download new jallib?!


‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۱۹:۵۲:۱۰ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 20, 2021, 12:20:48 PM4/20/21
to jallib
i downloaded last version JALlib
Thanks

but i yet can't send and receive data between two PICs

i clear my program
please see again my program

i send data from pic number 2 (B7.jal) to pic number 1(A7.jal)

when i pressed button1 from pic1 ,  i  send data with use "serial_hw_write(255)"  to pic2 .



‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۱۹:۵۴:۴۵ (UTC+4:30) نوشت:
PIC_2.zip

majid ebru

unread,
Apr 20, 2021, 12:23:47 PM4/20/21
to jallib
please help me
this is important for me


‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۰:۵۰:۴۸ (UTC+4:30) نوشت:

Rob CJ

unread,
Apr 20, 2021, 12:46:59 PM4/20/21
to jal...@googlegroups.com
Hi Majid,

Did your scross the wires? So TX of PIC1 is connected to the RX of PIC2 and the RX of PIC1 is connected to the TX of PIC2?

Also. I you want to test if the data is transmitted between the PICs, first minimize your program to see if that works before adding all other code.

I changed your code and simplified it to test the communication only

if a button is pressed on PIC1 it sends "1"to PIC2 and the LED on PIC1 goes off. If PIC2 receives a "1" the LED on PIC2 goes on. If a button is pressed on PIC2 it sends "2" to PIC1 and the LED on PIC2 goes off. If PIC1 receives a "2" the LED on PIC1 goes on.

If this works then you know your communication is working. 

See attached simplified programs. I did not test this since I do not have the hardware but the program speaks for itself.

Kind regards,

Rob




Verzonden: dinsdag 20 april 2021 18:23
Small_Demo.zip
Message has been deleted
Message has been deleted

majid ebru

unread,
Apr 20, 2021, 1:15:43 PM4/20/21
to jallib

Thanks from all that help me

👍👍👍👍👍👍💯💯💯💯💯

I almost can send and receive

Thank you very much

I try more .....
rob...@hotmail.com در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۱:۱۶:۵۹ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 20, 2021, 1:33:05 PM4/20/21
to jallib
Hi everybody

how can i rad data??

i use this code :

var byte char
forever loop
    if (serial_hw_read(char))    then block
         Out_3 = 1
       if char == 2 then
         Out_2 = 1
       end if
--- or ----
       if char == "2" then
         Out_2 = 1
        end if
     end block
    end if

-------------------
but when i send data ,  only "out_3" work and "out_2" don't work?!

should i convert "char"?

‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۱:۴۵:۴۳ (UTC+4:30) نوشت:

Rob CJ

unread,
Apr 20, 2021, 1:41:21 PM4/20/21
to jal...@googlegroups.com
Hi Majid,

You have to give some more info on what you try to achieve.

In your example you always make Out_3 equal to 1 and Out_2 only if char equals 2. Is that what you want or did you mean something like this:

forever loop
    if (serial_hw_read(char))   then 
        if char == 3 then
         Out_3 = 1
       elsif char == 2 then
         Out_2 = 1
       end if
    end if

Kind regards,

Rob


Verzonden: dinsdag 20 april 2021 19:33

majid ebru

unread,
Apr 20, 2021, 1:53:35 PM4/20/21
to jallib
no
out_3 just is sample for detective that i read data1

when PIC1send '2',how can i read that in PIC2??

----------------     PIC 1  -------
serial_hw_data = "2"

----------------  PIC2  ------------------

    if (serial_hw_read(char))    then block
--Out_3 = 1   --

       if char == 2 then
         Out_2 = 1
        end if
       if char == "2" then
         Out_2 = 1
        end if
     end block
    end if

------

but in PIC2 i can't set "out_2"??

how can i correctly  read data in PIC2?
rob...@hotmail.com در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۲:۱۱:۲۱ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 20, 2021, 1:57:54 PM4/20/21
to jallib
can i ask another  question??

if it is 20 meter distance between PICs , i should use RS232 or SPI?

so sorry and thanks a lot

‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۲:۲۳:۳۵ (UTC+4:30) نوشت:

majid ebru

unread,
Apr 20, 2021, 2:20:41 PM4/20/21
to jallib
  Rob and Kiste and Vasile 
Thank you very much to help me
🙏🙏🙏🙏🙏🙏🙏🙏🙏💯💯💯💯❤️❤️💐💐💐💐💐💐💐

I change program and I can send/receive with software serial

But I still can't correctly read data😢😥😫😢🤔🥺
‪majid ebru‬‏ در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۲:۲۷:۵۴ (UTC+4:30) نوشت:

Rob CJ

unread,
Apr 20, 2021, 2:27:40 PM4/20/21
to jal...@googlegroups.com
Hi Majid,

My mistake, if you send “1” you should use 
If  char == “1” then ...

Met vriendelijke groet,
Rob Jansen

From: jal...@googlegroups.com <jal...@googlegroups.com> on behalf of majid ebru <majid...@gmail.com>
Sent: Tuesday, April 20, 2021 8:20:41 PM
To: jallib <jal...@googlegroups.com>
Subject: Re: [jallib] How to send & receive data with interrupt in RS232
 

majid ebru

unread,
Apr 20, 2021, 3:08:44 PM4/20/21
to jallib
No , this is not true

i used this code

and you said this code in the old post

rob...@hotmail.com در تاریخ سه‌شنبه ۲۰ آوریل ۲۰۲۱ ساعت ۲۲:۵۷:۴۰ (UTC+4:30) نوشت:

Oliver Seitz

unread,
Apr 21, 2021, 12:28:44 AM4/21/21
to jal...@googlegroups.com
Hi Majid,

SPI is designed for centimeters, I don't think it can work reliably over 20 meters.

RS232 at 9600 baud is ok for 150 meters, if you're using real RS232 drivers and receivers like from the MAX232 series. The PIC controller does not have RS232, it has a usart which handles the NRZ protocol. This protocol is best known as being used by the RS232 interface. Therefore the protocol itself is commonly (but wrongly) referred to as "RS232"

RS232 uses negative voltages as a symbolic "1" and positive voltages for "0". At the receiving side, the voltage must at least go higher than +3V for "0" and lower than -3V for "1". At the sending side, voltages from up to +15V and down to -15V are used.

So, to answer your question in two simple sentences: RS232 is ok for the job. But RS232 is not what comes out of the controller.

Greets,
Kiste




Am Dienstag, 20. April 2021, 21:56:34 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:

vsurducan

unread,
Apr 21, 2021, 1:02:44 AM4/21/21
to jal...@googlegroups.com
Oliver, I remember the problems I had with an EIA232 with +/-8V output running at 800m at 9600bps. Everything works until due the transceiver heating the voltage dropped at +/-7.6V...:)
The length is given by the voltage at the level converter of the transmitter output. All level converters with charge pumps are not able to give more than +/-8V...+/-10V in the happiest circumstances.
Oldest/goldest EIA232 worked at +/-25V up to 2km.
For 20m you do noy need any level converter at the output of your PIC, just a twisted pair RX-GND TX-GND (CAT5 ethernet cable is perfect) and an open collector transmitter ( a gate) with pull-up resistor in the receiver end (at 20m distance from the transmitter).
However Majid,  I think you need first to learn jal and for that there is a learning curve which has to be passed....
Please start with the examples, compile them, make them run, modify them as you wish and post only when nothing works for you after three days of trying...this will help you more than you may believe right now...
best wishes

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Oliver Seitz

unread,
Apr 21, 2021, 1:32:54 AM4/21/21
to jal...@googlegroups.com
Thanks for the additional information, 800m is something very different from 20m ;-)

I can imagine that 20m at 5V ground-referenced is doable, but when you're starting, better stick to the specifications and try your luck when you have a bit of experience.

I myself am at a similar project, like 15 meter, and I want to use as little standby current as possible, and no twisted pairs. It's uni-directional, with constant-current pullup at the receiver and optically isolated pulldown at the sender with 1200 baud... First test of the concept in a few days ;-)

If standby current was of no concern, I'd use RS422 or RS485 drivers/receivers, true RS232 is old-fashioned and needs to many components.


Greets,
Kiste

Am Mittwoch, 21. April 2021, 07:02:46 MESZ hat vsurducan <vsur...@gmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/CAM%2Bj4qtaBjojssk_HHFK1M2dhhL9CNNf3mygd1F3nH0B5bck9A%40mail.gmail.com.

majid ebru

unread,
Apr 21, 2021, 1:52:01 AM4/21/21
to jallib
Thank you

Ok I use RS232.

But I can't read correctly data ,yet😫😢😫😢

Please guide me

When I send  "0x052" from pic1 , I received data in pic2 , but it is not correct


If serial_sw_read(char)) then block 
....
     lcd_cursor_position(1,5)
     print_byte_hex(lcd, char)     --  ====> print 2B
     lcd_cursor_position(1,10)
     lcd = char.    --.    ====> Print +
......

majid ebru

unread,
Apr 21, 2021, 2:14:46 AM4/21/21
to jallib
Now I can send and receive .

How should I send a number for example 987 to other PIC?
And
How should I read data ?

Rob CJ

unread,
Apr 21, 2021, 2:28:08 AM4/21/21
to jallib
Hi Majid,

I think it is time for you to start reading some stuff about JAL and how to use it with PIC.

3 Introduction JAL is a high-level language for PIC microcontrollers1 and originally developed by Wouter van Ooijen. JAL V2 (at this time of writing, the current version is V2.4n) is a re-write of the compiler, by Kyle York.

Kind regards,

Rob


Verzonden: woensdag 21 april 2021 08:14
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: NT: [jallib] How to send & receive data over medium distance
 

Oliver Seitz

unread,
Apr 21, 2021, 3:01:44 AM4/21/21
to jal...@googlegroups.com
To start, use a short connection, like 50cm maximum.

Transmit data which only has one bit (plus start bit) set, like

0x01
0x02
0x04

That way you can find out, if polarity and baud rate are correct.

I have a cheap scope, but it is good to see if the transmitter or the receiver doesn't work properly.

Greets,
Kiste


Am Mittwoch, 21. April 2021, 08:45:23 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
https://groups.google.com/d/msgid/jallib/5e7554f0-a1c8-45cb-a79f-1419870ed5fbn%40googlegroups.com
.

majid ebru

unread,
Apr 21, 2021, 3:29:11 AM4/21/21
to jallib

I search "serial" in JALV2 Tutorials.pdf ,it almost 90% just use serial_write or serial_data and it just use echo
I don't want to use echo,I want to chech data receive with other data.
I should get char(byte serial) and show that in LCD or use that in math formula.
 
Can show me ,which page contain data receive and check it?!

Thanks


Greets,
Majid

Oliver Seitz

unread,
Apr 21, 2021, 4:20:11 AM4/21/21
to jal...@googlegroups.com
Hi Majid,

it is about learning how to collect data. What you're expecting
are tutorials about

collecting data from i2c, outputting to LCD
collecting data from uart, outputting to LCD
collecting data from spi, outputting to LCD
collecting data from keypad, outputting to LCD
collecting data from SD-card, outputting to LCD
collecting data from ..., outputting to LCD

collecting data from i2c, outputting to internal RAM
collecting data from uart, outputting to internal RAM
collecting data from spi, outputting to internal RAM
collecting data from keypad, outputting to internal RAM
collecting data from SD-card, outputting to internal RAM
collecting data from ..., outputting to internal RAM

collecting data from i2c, outputting to external storage
collecting data from uart, outputting to external storage
collecting data from spi, outputting to external storage
collecting data from keypad, outputting to external storage
collecting data from SD-card, outputting to external storage
collecting data from ..., outputting to external storage

...

You won't necessarily find an exact solution to your needs as a step-by-step tutorial. Maybe you can find it, if you accept it to be in Arduino C, Turbo BASIC or COBOL.

You can ask questions here, like "How do I transmit and collect data in the numerical range from 0 to 1000000". You will get answers. If you ask, "How do I transmit and collect data in the numerical range from 0 to 1000000 over a 20 meter long cable, using interrupts, outputting it to a LCD and check for correct transmission using provided hardware", that does not require an answer but two days of engineer's work, or two weeks of teacher's work.

I recommend not to start with too complicated projects. If you need someone to take your hand and guide you from wherever to exactly there where you think you want to go, this is probably not the place. Jal is a language which has currently a limited userbase. If you're hoping to find someone to teach you all the steps to complete that single project, you might be more lucky if you choose a language with a larger userbase, like C.

Greets,
Kiste

Am Mittwoch, 21. April 2021, 09:36:33 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
https://groups.google.com/d/msgid/jallib/69c84bcb-2462-40be-bbff-179415d53bbfn%40googlegroups.com
.

majid ebru

unread,
Apr 21, 2021, 4:49:17 AM4/21/21
to jallib

Thanks

And so sorry

vsurducan

unread,
Apr 21, 2021, 8:11:19 AM4/21/21
to jal...@googlegroups.com
At 15m and 5V there is no problem with data sent in current. Using twisted wire cable is a good habit.
From the EMI perspective twisted cable it is about half as good as a shielded cable and has the parasitic capacity quite low compared with the shielded cable.
RS485 (standard 32 loads) is feasible at 1Km and quite high speed. Still there is an issue with the ground line and requires good terminators.
Data goes either on A&B plus ground cable (three wires between Tx and RX) or just A&B (two wire cable) and ground connected to earth on the transmitter and receiver end.
In the last configuration an issue is quite frequent caused by an offset (variable ground potential between TX and RX).
Also lightning is a problem for outdoor cables...and nothing help... :)... no matter how others will convince you to put three tranzorbs on each TX and RX  end.
happy communications!


majid ebru

unread,
Apr 21, 2021, 9:47:53 AM4/21/21
to jallib
RS485 is very powerful.

But I don't how to implement in PIC?!?

Is i2c the same rs485?!

Rob CJ

unread,
Apr 21, 2021, 9:54:19 AM4/21/21
to jal...@googlegroups.com
Hi Majid,

Please use Google to find out what RS485 and IIC is. Use the Jallib group for issues with libraries and the compiler not for general questions that you can easily find on the internet.

Thanks.

Kind regards,

Rob


Verzonden: woensdag 21 april 2021 15:47
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: NT: [jallib] How to send & receive data over medium distance
 

vasi vasi

unread,
Apr 21, 2021, 1:42:03 PM4/21/21
to jal...@googlegroups.com
The microcontroller boards that are used in Polish Universities are all equipped with (external - note for Majid) RS485 chips. 



--
Vasi

majid ebru

unread,
Apr 22, 2021, 2:48:51 PM4/22/21
to jallib
Hi 

Please help me again😢😢😫😫🥺🥺🤔🤔

When I connected two PICs together , everything is ok.

But when disconnect port serial , both PICs hanged ?!?!

Both micro stoped , and when connected again ,both micro work correctly?!

In fact both micro stopped in line : if  serial_sw_read(char)) then block ....

And doesn't run other codes🤔🥺😫😢

Why?!

How should I do ?!

Rob CJ

unread,
Apr 22, 2021, 2:53:23 PM4/22/21
to jal...@googlegroups.com
Hi Majid,

You have to provide more information. How do you know that they stopped? Did you narrow down the code down to the minimal size to show that it fails? If so you can share that code.

And to answer your other - not posted - comment. Due to the fact that you use this group to answer trivial questions that you can find on the Internet (which you should not do) and which are specific JAL or PIC related, your posts are now moderated. Only posts which are relevant to this group are passed on to the other group members.

Kind regards,

Rob


Verzonden: donderdag 22 april 2021 20:19

majid ebru

unread,
Apr 24, 2021, 12:20:36 AM4/24/21
to jallib

Please help me

I almost work with micro ,12 years ago .

Now I can't send / receive data?!

I should send and receive an integer(like adv value and ....) , but in serial_sw_data I just can send a byte ?!?!!!
And just read a byte with serial_sw_read(char)?!

I know that my kowlage about electronic is wake , but now I should do read&write data?!

Please guide me,🙏🙏🙏🙏🙏🙏🙏🙏

Rob CJ

unread,
Apr 24, 2021, 1:36:57 AM4/24/21
to jal...@googlegroups.com
Hi Majid,

If you want to send an integer value you indeed have to send it in bytes. But that thouls be faily easy with JAL.

If have for example a variable of type word you can do the following

var word my_word_variable
var byte  my_byte_variable_low at my_word_variable
var byte my_byte_high at my_word_variable + 1

You can then send both 'my_byte' variables separately and in the other PIC you do the same, read the two bytes which are mapped to a word.

Als see the documentation of the JAL compiler.

Kind regards,

Rob


Verzonden: vrijdag 23 april 2021 19:47

Oliver Seitz

unread,
Apr 24, 2021, 2:07:21 AM4/24/21
to jal...@googlegroups.com
Hi Majid,

what Rob said is of course true, but it is a bit short. That simple method relies on the receiver never to miss a byte. You should use some kind of sync to enable the receiver to check if it does not confuse lo- and hi-bytes.

When it's ADC results, you can use the "unused bits" of the word. ADCs on 8bit PICs have a maximum of 12 bits, so if a received byte has one of the four upmost bits set (that is, if (value & 0b11110000) !=0 ) , it must be the lower byte. If you check those bits on every byte you presume to be a high byte and the check fails, you can just drop that one byte and you're back to sync again.

I myself prefer to use ASCII over binary whenever the speed allows that. If I'm struck by lightning, someone else can just connect a computer terminal and read what's happening. Furthermore, there are CR/LF characters defined for sync purposes. And, there are libraries to simplify the sending part a real lot.

Greets,
Kiste


Am Samstag, 24. April 2021, 07:36:58 MESZ hat Rob CJ <rob...@hotmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/AM0PR07MB6241CB67E4CBAE8CFD01D0D0E6449%40AM0PR07MB6241.eurprd07.prod.outlook.com.

vsurducan

unread,
Apr 24, 2021, 2:28:36 AM4/24/21
to jal...@googlegroups.com
Majid, one good practice when you're testing communication between two embedded systems (A and B) is to check each one with a terminal first.

Assuming A is sending to B and B receives and does something on IO port, test first the TX of A to the computer terminal, then RX of B from the computer terminal. After that, only if each one works ok, connect TX/RX of A with B.  Some good free terminals for this job (search for:) Realterm, Teraterm, Termite. You may also need a hardware converter which depends on your computer (if you have a real COM port with RS232 levels or just an USB/RS232 with 3.3V or 5V levels).
                            
This approach will protect you from a lot of trouble and make you understand if a byte, a word, an ASCII or something else is truly sent/received and was sent/received in the right order.

Simplify your work by sending and receiving ASCII symbols first and then understand all the used procedures from the libraries (this is mandatory to unders
tand which is your fault/misunderstanding or which is the software bug... there are bugs in any software...:) ).


majid ebru

unread,
Apr 24, 2021, 2:49:31 AM4/24/21
to jallib
Thank all

But I need sample code for read.

Almost ,all documents use write code and I didn't saw read code.

Oliver Seitz

unread,
Apr 24, 2021, 2:57:09 AM4/24/21
to jal...@googlegroups.com

var dword collect_input=0
var dword received_input=0
var byte new_input

forever loop
  if serial_hw_data_read(new_input) then
    if (new_input>="0") & (new_input<="9") then
      collect_input=collect_input*10
      collect_input=collect_input+new_input-"0"
    end if
    if (new_input==13) | (new_input==10) then
      received_input=collect_input
      collect_input=0
    end if
  end if

end loop

It's meant as inspiration. I have not tested it, just typed it into the email editor.

Greets,
Kiste



Am Samstag, 24. April 2021, 08:49:33 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
https://groups.google.com/d/msgid/jallib/b32a5de8-117c-4c73-a771-5ba9a493b45cn%40googlegroups.com
.

majid ebru

unread,
Apr 24, 2021, 3:00:35 AM4/24/21
to jallib
For example,I want to send 642 ....

I use this code in sender
...
Serial_sw_data = 6
Delay_1ms(2)
Serial_sw_data = 4
Delay_1ms(2)
Serial_sw_data = 2
Delay_1ms(2)
...

But in receiver , I can't read correctly.

Var byte Temp[3]
Var byte i = 0
For loop
  If serial_sw_read(char) then
    Temp[i] = char
     Print_string(lcd,Temp[i])
     i = i + 1
     If 2 < i then i = 0 end if
End loop

Oliver Seitz

unread,
Apr 24, 2021, 3:07:40 AM4/24/21
to jal...@googlegroups.com
You're sending binary and trying to receive ad ASCII






Am Samstag, 24. April 2021, 09:00:37 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
https://groups.google.com/d/msgid/jallib/2ac2d829-8399-4e1f-b7e2-1dfb83be12een%40googlegroups.com
.

Rob CJ

unread,
Apr 24, 2021, 3:29:22 AM4/24/21
to jal...@googlegroups.com
Hi Majid,

If you want to print it  - as ASCII -on the receiving side, change

temp[i] = char 
by
temp[i] = char + "0"

Then you can print it.

Kind regards,

Rob


Van: 'Oliver Seitz' via jallib <jal...@googlegroups.com>
Verzonden: zaterdag 24 april 2021 09:07
Aan: jal...@googlegroups.com <jal...@googlegroups.com>

majid ebru

unread,
Apr 24, 2021, 5:21:43 AM4/24/21
to jallib
Hi

It isn't important that I read ASCII or .... .
It is important that I read true.

Thanks , I will test and I say result.

Oliver Seitz

unread,
Apr 24, 2021, 5:53:56 AM4/24/21
to jal...@googlegroups.com
It is important whether you use one or the other. If the sender speaks tagalog, and the receiver expects to hear mandarin, they won't be able to communicate.

Greets,
Kiste






Am Samstag, 24. April 2021, 11:49:49 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:





Hi

It isn't important that I read ASCII or .... .
It is important that I read true.

Thanks , I will test and I say result.

On Saturday, April 24, 2021 at 11:59:22 AM UTC+4:30 rob...@hotmail.com wrote:
>  
>  
>  Hi Majid,
>
>  
>
>
>  If you want to print it  - as ASCII -on the receiving side, change
>
>  
>
>
>  temp[i] = char 
>
>  by
>
>  temp[i] = char + "0"
>
>  
>
>
>  Then you can print it.
>
>  
>
>
>  Kind regards,
>
>  
>
>
>  Rob
>
>  
>
>
>
> ________________________________
> Van: 'Oliver Seitz' via jallib <jal...@googlegroups.com>Verzonden: zaterdag 24 april 2021 09:07Aan: jal...@googlegroups.com <jal...@googlegroups.com>
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/21329211-66fc-4dda-a32d-da472e0be127n%40googlegroups.com.

majid ebru

unread,
Apr 24, 2021, 9:26:21 AM4/24/21
to jallib

Hi again

I'm very confused.

Why can't I send and receive?!?😫😫😫😫

I tested both codes,integer and ASCII code , but I read incorrect data.

What is your suggestions ?!

Oliver Seitz

unread,
Apr 24, 2021, 10:26:53 AM4/24/21
to jal...@googlegroups.com
did you ever try the suggestion about connecting a computer terminal? I'd recommend minicom on linux.
Did you ever send "hello world" to the LCD? Did you send 123? And 1 2 3? And the result of 3*12?

If you haven't released a baloon and thrown a paper plane, don't try to become a rocket scientist.

Greets,
Kiste







Am Samstag, 24. April 2021, 15:31:43 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/6cc6adff-f8dc-4e70-999b-f72c53a0cdbbn%40googlegroups.com.

majid ebru

unread,
Apr 24, 2021, 10:35:20 AM4/24/21
to jallib
Hi

PIc1(sender) :
forever loop
    if btn1 then block
        serial_sw_data = "9"
        delay_1ms(5)
    end if
end loop
---------------------------------------------

PIc2(receiver) :
forever loop
    if (serial_sw_read(char)) then block
         lcd_cursor_position(1,1)
         print_byte_dec(lcd, char+ "0")  -- ==> i see in LCD :  147
----------
         lcd_cursor_position(1,8) -- ==> i see in LCD : (  c  )  --  character c
         lcd = char
     end block
    end if
end loop
---------------------------------------------

majid ebru

unread,
Apr 24, 2021, 10:38:04 AM4/24/21
to jallib
i use proteus  .

in this programs , i see "9" in  output oscilloscope  and i see 147 and c in LCD.

Oliver Seitz

unread,
Apr 24, 2021, 10:54:34 AM4/24/21
to jal...@googlegroups.com
So you're sending 57 (=0b00111001 or "9") and receiving 99 (=0b01100011 or "c").  Could be reverse polarity.



Am Samstag, 24. April 2021, 16:41:57 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/a9767826-dfdc-4b91-ba9f-ae9f6b909102n%40googlegroups.com.

majid ebru

unread,
Apr 24, 2021, 11:35:50 AM4/24/21
to jallib
Reverse polarity?!
Sorry but how do I do that?!

Rob CJ

unread,
Apr 24, 2021, 12:13:59 PM4/24/21
to jal...@googlegroups.com
Hi Majid,

Discussing this without any sample program doet not help to analyze the problem.

Back to my previous question. Did you minimize the program so that you are only testing the communication?

Can you send a sample program and maybe also a schematic diagram of the hardware you are using?

Kind regards,

Rob


Verzonden: zaterdag 24 april 2021 17:35

majid ebru

unread,
Apr 24, 2021, 12:53:09 PM4/24/21
to jallib
Thank you
this is minimum.
min.zip

Oliver Seitz

unread,
Apr 24, 2021, 1:28:18 PM4/24/21
to jal...@googlegroups.com
Master has

"const serial_sw_invert = true"

Slave has

"const serial_sw_invert = false"

That is what I meant by mismatched polarity






Am Samstag, 24. April 2021, 19:19:14 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/ba6350c9-9579-4abf-a458-2e62adb6ee97n%40googlegroups.com.

majid ebru

unread,
Apr 24, 2021, 1:50:50 PM4/24/21
to jallib
oh my god

if i change this bit , i don't have any communication between PICs.
just in this mode(Master = "const serial_sw_invert = false" and Slave "const serial_sw_invert = true"  , you write mistake )
, i can send/receive and in other modes , i can't send/receive and PICs stopped (because i have a led  for blanking ,in other modes led doesn't work)

how do i do for solve?

Oliver Seitz

unread,
Apr 24, 2021, 2:11:41 PM4/24/21
to jal...@googlegroups.com
Hi Majid,

no need to call me "god", "excellency" would highly suffice.

You have been told to use serial_hw_int_cts, as serial_software is always a blocking read?

Yes, your program HAS TO STOP DOING ANYTHING ELSE, while serial_software listens for data on its input pin.

I'm starting to ask myself, what for do I explain all that lot, if you choose to ignore most of my words?

Greets,
Kiste




Am Samstag, 24. April 2021, 19:57:01 MESZ hat majid ebru <majid...@gmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/eb5ba40e-eb8f-43c6-a31f-eb61c0dccdc5n%40googlegroups.com.

majid ebru

unread,
Apr 24, 2021, 2:27:46 PM4/24/21
to jallib
Hi and sorry
i don't call you god.
you are a good man and i thanks you
Ok
i will change my board

vsurducan

unread,
Apr 25, 2021, 2:45:58 AM4/25/21
to jal...@googlegroups.com
Hi Majid,
I'm trying again to explain again that a success or a failure is caused just by your own actions despite any good intentions of his excellency Kiste
You are alone in front of your computer with your code and your hardware..

Any software language has a learning curve which can not be bypassed. Any hardware acknowledges have to be acquired step by step.
Read carefully the microcontroller datasheet (at least the EUSART module) and the application notes dealing with level converter, inverting or not the signals, etc.

So, once again: read several times the libraries and samples dealing with USART from the JallibWorkplace folder (assuming you have it installed).
Start playing your code with blink a LED`sample. Once that works for you without problems test one of the examples of EUSART communication.

If that works too, start modifying that example with your own code until it works as you wish.
BTW: what exactly would do this communication at 20m distance between two PICs? Which is your final goal?
best wishes

Rob CJ

unread,
Apr 25, 2021, 2:50:52 AM4/25/21
to jal...@googlegroups.com
Hi Majid,

I would not recommend to use serial softwaer since, as Kiste says, it will not work as soon as your program is doing something else (like in your case controlling an LCD).

You better use - as mentioned earlier - the serial_hw_int_cts but you need to change your schematic since this only works on the TX and RX pins of the PIC so RC6 and RC7, not RC4 and RC5.

What happend to the small sample programs I has sent you that where based on your initial program? Did you use them to test?

I noticed this. In you schematic diagram you have no crystal connected to your PIC but in your program you mention a clock of 8 MHz. The PIC16F877A does not have an internal clock of 8 MHz so you program will never work. You either connect a crystal of 20 MHz, change your pragma clock to 20 MHz or use a PIC that does have an internal oscillator.

Kind regards,

Rob


Verzonden: zaterdag 24 april 2021 20:27

majid ebru

unread,
Apr 26, 2021, 1:44:05 PM4/26/21
to jallib
Thanks form all

Thanks alot

after i changed  my schematic diagram  ,I finally could send or receive data correctly .

when i send "A" from master PIC, i receive and show "56" in LCD in salve.

everything is OK.

i can ask anther question ?!?
or
i should new post??

how can i send  and receive string??

now when i send "ABCD" from master PIC to slave,i receive 65,66,67,68 and it's OK.

how can i detect that data finished?!?

Rob CJ

unread,
Apr 26, 2021, 1:57:08 PM4/26/21
to jal...@googlegroups.com
HI Majid,

Good to hear. What did you change in your schematic diagram? It can help others to learn too.

If you want to know the end of a string you could send a carriage return or a line feed at the end or your string (or both) and detect that character in your receiving PIC.

For example a carriage return is "\r" so if you have a string like: 

const byte my_string[] = "ABCD\r" and send that character by character, your receiving PIC should check for the "\r" to determine the end of the string.

And yes it would have been better to post a new question.

BTW. The Jallib google group is for reporting bugs. The Jallist google group is for asking questions about the use of JAL. So this new post should have been in the Jallist group. But always start by reading the JAL compiler description to prevent that you are asking questions which you could have found in reading the manual. Note that neither of the groups are meant to learn you how to program. It is assumed that you know how to program. If not you should follow a course or read a boot about it and ..... .practice.

Kind regards,

Rob



Verzonden: maandag 26 april 2021 19:44

majid ebru

unread,
Apr 26, 2021, 10:55:28 PM4/26/21
to jallib

Thank you Rob

I just connected Rx and Tx(I think pin.c6 and pin.c7) to other PIC and i change the program
Now I can't send my program,but as soon as possible, I will send those.

Thanks a lot again

Kind regards,majid

majid ebru

unread,
Apr 27, 2021, 11:05:20 PM4/27/21
to jallib
Hi all

PIC1:
;@jallib section chipdef
-- chip setup
include 16f877a
pragma target clock 8_000_000 -- xtal frequency
pragma target OSC hs
pragma target WDT disabled
pragma target LVP disabled
enable_digital_io()
include delay
----------------------------
;@jallib section serial_software
--
const serial_hw_baudrate = 9_600
--alias serial_ctsinv is pin_B4
var bit serial_overflow_discard = true
--
include print
include serial_hw_int_cts
serial_hw_init()
-------------------------------
forever loop
-------- btn1
 if in1 == 1 then
  print_string(serial_hw_data, "ABCD")
 end if
end loop

-------------------------_____________#####

PIC2
;@jallib section chipdef
-- chip setup
include 16f877a
pragma target clock 8_000_000 -- xtal frequency
pragma target OSC hs
pragma target WDT disabled
pragma target LVP disabled
enable_digital_io()
--------------------------
-------------------------- LCD ------------------------------------
const byte LCD_ROWS = 2 -- LCD with 2 lines
const byte LCD_CHARS = 16 -- and 16 char1acters per line
--
alias lcd_en is pin_B3 -- data trigger
alias lcd_rs is pin_B2 -- command/data select.
pin_B3_direction = output
pin_B2_direction = output
--
alias lcd_d4 is pin_D3
alias lcd_d5 is pin_D2
alias lcd_d6 is pin_D1
alias lcd_d7 is pin_D0
--
pin_D3_direction = output
pin_D2_direction = output
pin_D1_direction = output
pin_D0_direction = output
--
include lcd_hd44780_4
---- init the lcd controller
lcd_init()
lcd_clear_screen() --
------------------------------------------------------------------ Setup USART
const serial_hw_baudrate = 9_600
--alias serial_ctsinv is pin_B4
var bit serial_overflow_discard = true
--
include serial_hw_int_cts
include print
serial_hw_init()
-------------------------------------------------------------------
var byte press = 4
var byte char1
-------------------------------------------------------------------
forever loop
---------------------------------------- Serial
 if (serial_hw_read(char1)) then block
   lcd_cursor_position(0,press)
   lcd = char1
   lcd_cursor_position(1,press)
   print_byte_dec(lcd, char1)
   press = press + 4
   if 15 < press then press=4 end if
 end block end if
------------------------
end loop
Reply all
Reply to author
Forward
0 new messages