Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

12 Bit Parallel to Serial conversion 16F627

Status
Not open for further replies.

Horizon

New Member
I'm building a tide level data logger. I've finished the electronics hardware. It can measure a tidal range of 4 metres with a resolution of 1 mm.
The output is a 12 bits of parallel data.
I need to send this over a wired serial conection. Data rate can be slow since it only has to be read once every few minutes.

I'm trying to use the UART in a 16F627. The parallel data is input on Port A for the LS 8 bits. The most significant 4 bits are on RB 4,5,6,7

I can get the UART to send fixed constants or text (Hello World) and I can read it over the serial link. However, I just can't seem to read the data from the input pins. I always seem to end up just sending zero whatever data I put on the inputs. It's a long time since I did any of this stuff, I think I'm missing something obvious, but as an older person, the obvious gets harder and harder to spot.
Any help would be appreciated.

Code:
'12 bit Parallel to Serial by Derek Hodge
'11 Oct 2013
'Device 18-pin 16F627A
'Inputs RA0 - RA7 , RB4, RB5, RB6, RB7
'serial out TX Pin 8


Define CONFIG = 0x3f18
Define CLOCK_FREQUENCY = 4


AllDigital
Hseropen 4800


TRISA = 0xff  'Set Port A as input.  Have also tried this using CONFIGPIN but same result


TRISB = 0xf0  'Set  most significant 4 bits of PORT B as input
Dim ls8 As Byte  'LS 8 bits

Dim ms4 As Byte  'MS 4 bits

loop:
PORTA = ls8
PORTB = ms4
Low ms4.0  'Make sure LS bits are 0
Low ms4.1
Low ms4.2
Low ms4.3
ms4 = ShiftRight(ms4, 4)  'Move the data bits from most significant positions to LS positions

Hserout ls8, ","

Hserout ms4, CrLf
WaitMs 500


Goto loop
 
You appear to be writing variables (ls8 & ms4) to your port pins.

Try changing,
Code:
PORTA = ls8
PORTB = ms4
To,
Code:
ls8=PORTA
ls4=PORTB

Mike.
 
Hi Mike,
now it's official "I'm an idiot"!
Amazing how hard it is to spot your own mistakes, even when it's obvious to someone else.
I just tried it and now everything is fine.

Thanks again for your help.

Derek
 
Hi Mike,
Amazing how hard it is to spot your own mistakes, even when it's obvious to someone else.
Derek

We've all done it. It's easy to get blinded when looking for why it doesn't work. I find that explaining how code works to someone else works wonders for spotting these kind of things, even a teddy bear works.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top