Hi all, if i was using a software usart to read data from an input pin, do i have to use a particular pin on a given chip say a 16f877 or similar, and if not is there a maximum amount of pins that could be used, not all at the same time of course, and how would i change which pin is being read.
Hi all, if i was using a software usart to read data from an input pin, do i have to use a particular pin on a given chip say a 16f877 or similar, and if not is there a maximum amount of pins that could be used, not all at the same time of course, and how would i change which pin is being read.
You can use as many input pins as you like, check my tutorials for suitable routines. The easiest way would be to have a seperate subroutine for each input pin, as the routine is only small this wouldn't be a problem - the routines could all share the same delay routines.
thankyou now im getting somewhere although i must admit im finding this assembler a task to say the least, you couldnt by any chance lend me some IQ for a while could you nigel Oh yes thats exactly what you do do on this forum..... MORE MORE lol
You can use as many input pins as you like, check my tutorials for suitable routines. The easiest way would be to have a seperate subroutine for each input pin,
You can use as many input pins as you like, check my tutorials for suitable routines. The easiest way would be to have a seperate subroutine for each input pin,
This is the actual receive subroutine, the port and pin are defined in SER_PORT and SER_IN.
Code:
Rcv_RS232 BTFSC SER_PORT, SER_IN ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC SER_PORT, SER_IN ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF Bit_Cntr
CLRF Rcv_Byte
Next_RcvBit CALL Bit_Delay
BTFSS SER_PORT, SER_IN
BCF STATUS , C
BTFSC SER_PORT, SER_IN
BSF STATUS , C
RRF Rcv_Byte , f
DECFSZ Bit_Cntr , f ;test if all done
GOTO Next_RcvBit
CALL Bit_Delay
MOVF Rcv_Byte, W
RETURN
The equates in that particular example (tut7_1.asm) are:
For your purpose of multiple input pins, I would suggest NOT using equates, and manually setting the port and pin in each seperate subroutine to the pin you require. I would suggest naming the subroutines 'sensibly', something like 'Rcv_RS232_B1', 'Rcv_RS232_A2' etc.
Since you don't seem to have a clue on where to begin, let me make a few assumptions on what you intend to do. First, only one pin at a time is being sampled. Second, you want to save on code and write a common serial receive routine for all port pins.
Therefore, the example above no longer applies because it is hard coded to a particular port pin. No problem. Here is a code sample that should work on all ports.
Code:
;
; Set to 1 the bit of the particular port you want to sample
; Set all other bits to 0.
;
PORTA_MASK EQU 20h ; 20h-24h are arbitrary memory locations
PORTB_MASK EQU 21h
PORTC_MASK EQU 22h
TEMP EQU 23h
SERIAL_IN EQU 24h
MOV PORTA,W ; read PORTA
ANDWF PORTA_MASK,W ; mask out unused pins
MOVWF TEMP ; store into temporary register.
MOV PORTB,W ; read PORTB
ANDWF PORTB_MASK,W ; mask out unused pins
IORWF TEMP,F ; store into temporary register.
MOV PORTC,W ; read PORTC
ANDWF PORTC_MASK,W ; mask out unused pins
IORWF TEMP,F ; store into temporary register.
CLRC
SKPZ
SETC
RRF SERIAL_IN,F
Now, if you want to work with several port pins concurrently, there is a very old application note at the Microchip's website that shows how to do concurrent tasks. It even has a code sample for two concurrent software serial routines.
How old? It was originally written for the PIC16C5X family.
yes only one pin at a time needs to be read, and the smaller i keep the routine the easier it will be for me to understand what is going on.
It is hard to wade through everything and just pick out what i need to do to get where i want to be with a particular project,when what seems in my head to be a simple concept seems so hard to do without the experience you guys have no matter how many times i read the data sheets. If i knew someone in person i think a real time chat would make it much easier but i dont so i come on here and if i look stupid then so be it, as long as you guys dont get bored educating me.
Now, if you want to work with several port pins concurrently, there is a very old application note at the Microchip's website that shows how to do concurrent tasks. It even has a code sample for two concurrent software serial routines.
well the way i understand it (correct me if i am wrong) if i am recieving two or more lots of data at 4800 baud each and the outgoung data
has to be at 4800 baud then i can or will have to sacrifice at least 50% of the combined incoming data just to get it out again.at the correct baud.
well the way i understand it (correct me if i am wrong) if i am recieving two or more lots of data at 4800 baud each and the outgoung data
has to be at 4800 baud then i can or will have to sacrifice at least 50% of the combined incoming data just to get it out again.at the correct baud.
The 16F877 has a hardware USART, you can use that as the single serial output - that takes care of all your transmission worries, without taking any time up (other than a few microseconds, with a 4MHz clock).
Hi
A standard NMEA Talker sends out 1-3 sentences per second
(depending on the type of talker and length of the sentence, max 80 characters)
The standard baudrate is 4800
If i was to use just two inputs would the pic be able to collect ALL the data from two inputs, sort it and send it without missing any data?
Hi
A standard NMEA Talker sends out 1-3 sentences per second
(depending on the type of talker and length of the sentence, max 80 characters)
The standard baudrate is 4800
If i was to use just two inputs would the pic be able to collect ALL the data from two inputs, sort it and send it without missing any data?
I think you should buffer one full sentence before retransmission to assure you don't mixup sentences from two channels. It would simplest to use two buffers, one per input.
thanks motion, but the more i look into this the more negative i feel about using one pic to do it, im told from more than one source that reading information from more than one nmea talker (4800baud serial input with upto 80 characters) is just not possible without loosing data. i am begining to believe them. Of course if i was to use an atmel im told it is feasable but not with a pic, all the information i can get would suggest that the only way to do it with the pic chip would be to use a 12f for every nmea talker each buffering while information is read from other sources. and a master pic to collect all the information and send it out
I can write an assembly language program for a PIC16F876 running @20Mhz that can receive from a least a couple of bit-banged serial ports @4800baud. I'd sample the port pins at 4X the baud rate (19.2K per sec) under interrupt from a "Special Event Trigger". Using a 40Mhz PIC18F452 would add speed and more memory for additional channels. This would be much easier than using multiple slave PICs and trying the make them talk to a master PIC.
Having said all that, unless you have substantial experience working with PICs and interrupts, it would sound impossible to do. Using an Atmel ATMega with two hardware uarts and writing in C language would greatly simply things. So, I can understand other people coming up with the above conclusion.
BTW, here is a link to an integrated uart and rs-232 tranceiver from maxim, the maker of the popular max232. I think you can connect at least a couple of these to the spi port. This should solve the extra uart problem.
Bit banging is quite tough on resources. It's a bit tough to perform other functions while reading the serial port, especially if you're doing oversampling on the signal.
Ok im not good a wording what im thinking which may be why my coding is so bad but i will give it a go:
would a pic be fast enough to do it like this:
memory locations from A01-A99 & B01- B99
read byte from pin 1 into memory location A01
is byte "crlf"
if yes move from memory location A** to tx & clear memory reset memory location to A01
if no increment memory location A01
read byte from pin 2 into memory location B01
is byte "crlf"
if yes move from memory location B** to tx & clear memory reset memory location to A01
if no increment memory location B01