PDA

View Full Version : 12f675_fuse_about_to_blow!



Pages : 1 [2] 3 4

LEDave
- 10th April 2010, 16:34
Cheers mackrackit, your time and effort appreciated as ever.

Another LEDave question though. Does the 'serial communicator' have to be installed on both machines? Or can I configure Com Port1 (on the old pc) through the DELL.

Dave

mackrackit
- 10th April 2010, 18:28
Not sure I understand that one.
Instal MCS on both machines. I think ?

LEDave
- 10th April 2010, 19:01
Instal MCS on both machines

Yes, does MCS need to be on both machines to make this work, or can the communicator be set up / work over a network.

Dave

mackrackit
- 10th April 2010, 19:32
You will need MCS on the machine that you are writing code/ programing the PIC on and also on the machine you are going to use for the serial comunication.

LEDave
- 10th April 2010, 19:43
Cheers,

I'll load it up.

Dave

LEDave
- 10th April 2010, 22:02
I loaded the program and setting is : com1 : 2400baud : No parity :byte size 8 : 1 stop bit.

I typed 3 into the transmit window (it shows a flashing green connected bottom left hand side of screen) and at the bottom middle is says bytes TX: 1 : bytes RX:0

After a while though it suddenly said: TX: 1 RX: 330 and a row of 'yyyyyy's in the received box.

I've tried it several times since though and back to: TX1 RX:0

So nearly there? Very exciting though I must say.I feel like Marconi....:cool:

Also the LED's on GPIO.5 didn't light up.

mackrackit
- 10th April 2010, 22:29
Marconi??????
Tesla!!!

If you do not figure it out in a bit. Post the configs/code and tell us again how everything is connected.

Being that it returned something once makes me think something might be loose.

LEDave
- 10th April 2010, 22:56
Being that it returned something once makes me think something might be loose

Well it could be. Although I've just realised that it only posted the 'yyyyy's when I reloaded the program.

Speaking of program, could that be the problem (don't forget I'm still the worst programmer in the Northern hemisphere right now)


CMCON0 = %00000111
ANSEL = %00000000
TRISIO = %00000000
GPIO = %00000000

DEFINE SER2_BITS 8

MYVAR VAR BYTE

MAIN

serin2 GPIO.0, 2400,[DEC MYVAR]

IF MYVAR = 3 THEN HIGH GPIO.5


Tesla_Dave

mackrackit
- 10th April 2010, 23:52
Hint...


serin2 GPIO.0, 2400,[DEC MYVAR]

Take another look at the manual and appendix B , I think it is B, MODE number.

Then add a short pause maybe 1/4 second, and a GOTO MAIN

MAIN:

LEDave
- 11th April 2010, 00:39
I've tried this but it doesn't compile, do I need the 2400baud as well?

serin2 GPIO.0, Mode = 396, [DEC MYVAR]

LEDave
- 11th April 2010, 00:40
I've tried this but it doesn't compile, do I need the 2400baud as well?


serin2 GPIO.0, Mode = 396, [DEC MYVAR]

mackrackit
- 11th April 2010, 00:50
From the manual


' Wait until the character “A” is received serially on Pin1 and put next character into B0
SERIN2 1,16780,[wait (“A”),B0]

' Skip 2 chars and grab a 4 digit decimal number
SERIN2 PORTA.1,84,[skip 2,dec4 B0]

SERIN2 PORTA.1\PORTA.0,84,100,tlabel,[wait (“x”, b0), str ar]

LEDave
- 11th April 2010, 00:52
This was my last go for tonight (wouldn't compile though).

I'm going to sleep on it.

Cheers again mackrackit, see you tomorrow.


CMCON0 = %00000111
ANSEL = %00000000
TRISIO = %00000000
GPIO = %00000000

DEFINE SER2_BITS 8

con mode = 396

MYVAR VAR BYTE

MAIN

serin2 GPIO.0, 2400,mode, [DEC MYVAR]

IF MYVAR = 3 THEN HIGH GPIO.5
PAUSE 250
GOTO MAIN

Tesla_Dave

mackrackit
- 11th April 2010, 11:02
Might be another problem...

If all of the PicKIt1 are the same, mine has GPIO.0 connected to the on-board POT (RP1).

Your code is still a bit off, but code will not fix hardware.

Maybe I am looking at the hardware wrong, exactly what do you have? Maybe a picture?

LEDave
- 11th April 2010, 18:53
Hi mackrackit,

I've re-cheched my connections:


PIC12F683 on my PICKit1.

I've got common pin5 on the DB9 cable (yellow) going to VSS PIC pin8.

I've got pin3 on the DB9 cable (red) going to GPIO.0 PIC pin7.

And pin2 on the DB9 cable (brown) going to GPIO.2 PIC pin5.





Pin 5
Common, ground, zero rail...
This must be connected to both devices for any serial to work.

Pin 2
Data is sent to the PC via this pin. PIC® -->> PC

Pin 3
Data is sent to the PIC® via this pin. PIC® <<-- PC

So data is coming from the pc onto GPIO.0

data is going from the PIC to pc on GPIO.2

How does that look / sound?

Dave

LEDave
- 11th April 2010, 19:41
I've added 'modedefs.bas' and set mode '0' still no joy:(


CMCON0 = %00000111
ANSEL = %00000000
TRISIO = %00000000
GPIO = %00000000

DEFINE SER2_BITS 8

INCLUDE "modedefs.bas"

MYVAR VAR BYTE

MAIN

pause250

serin2 GPIO.0, 0, [DEC MYVAR]

IF MYVAR = 3 THEN HIGH GPIO.5
PAUSE 250
GOTO MAIN

mackrackit
- 11th April 2010, 19:59
CMCON0 = %00000111
ANSEL = %00000000
TRISIO = %00000000
GPIO = %00000000

MYVAR VAR BYTE

MAIN:
PAUSE 250
SERIN2 GPIO.0, 16780, [DEC MYVAR] '2400 INVERTED
IF MYVAR = 3 THEN HIGH GPIO.5
PAUSE 250
GOTO MAIN

But if GPIO.0 is connected to the POT it may not work.

LEDave
- 11th April 2010, 21:04
Hi mackrackit

I've metered GPIO.0 out to the pot, it does seem to be connected(getting some strange readings though).

I then changed the cable from GPIO.0 to GPIO.4 (and the program to reflect the change) when I send from the serial communicator two LED's briefly flash on then off ( pretty quick though).

I increased the pause time from 250 to 2000, still only a brief flash but definately
flashing!

Dave

mackrackit
- 11th April 2010, 21:24
Two LEDs ???

GPIO.4 is connected to a LED ?

If you have a 14 pin chip try it. I think some of the pins from a 14 will go directly to the J3 header.

Making progress though!!!

LEDave
- 11th April 2010, 21:32
Hi mackrackit

Was getting there, I say was because every time I try and load a program now 'checksum verify failed' appears.Any ideas on that one.

Dave

mackrackit
- 11th April 2010, 21:38
Disconnect the serial cable from the PC?

LEDave
- 11th April 2010, 21:43
Disconnect the serial cable from the PC?

Cured 10-10 mackrackit:cool:

I'll change chips in a mo'

Dave

mackrackit
- 11th April 2010, 21:46
GPIO.0 and 1 are programming pins.

At times they need isolated when squirting the code into the chip.

LEDave
- 11th April 2010, 22:27
Here's the latest code, doesn't work though:(

Is it ok to leave the PIC - pc cable unplugged? If not where should it go?

The PIC is a 16F684


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

MYVAR VAR BYTE

MAIN:
PAUSE 250
SERIN2 PORTA.0, 16780, [DEC MYVAR] '2400 INVERTED
IF MYVAR = 3 THEN HIGH PORTA.5
PAUSE 250
GOTO MAIN

Dave

mackrackit
- 11th April 2010, 22:41
Try changing the wire from the PC, pin 2 on the DB9 to PORTC.4. I think it goes directly to the J3 header.

PORTA.0 is still going through the POT and is a programming pin.

LEDave
- 11th April 2010, 22:58
Try changing the wire from the PC, pin 2 on the DB9 to PORTC.4. I think it goes directly to the J3 header.

Getting confused here, I thought data was sent to the PC via pin 2?


Pin 2
Data is sent to the PC via this pin. PIC® -->> PC

mackrackit
- 11th April 2010, 23:00
OOPPPSSS!!!!!!!

I goofed.

Sorry.

LEDave
- 11th April 2010, 23:07
OOPPPSSS!!!!!!! I goofed. Sorry.

Hey even Marconi got his wires crossed from time to time I'm sure:cool:

I've got the red wire from pc (pin3 db9) going to PORTC.5 (fourth one down on the jumper).

Here's the latest prog:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

MYVAR VAR BYTE

MAIN:
PAUSE 250
SERIN2 PORTC.5, 16780, [DEC MYVAR] '2400 INVERTED
IF MYVAR = 3 THEN HIGH PORTA.5
PAUSE 250
GOTO MAIN

mackrackit
- 11th April 2010, 23:39
That chip defaults to 4 MHz so you will want to add

DEFINE OSC 4
to the beginning of your code.

Make sure you can blink an LED at an expected rate.

LEDave
- 11th April 2010, 23:46
Hey mackrackit, I think we've cracked it:)

Instead of just sending a '3' over from the transmit box which didn't work, I changed it to 'DEC:3' clicked send and the LED's lit for 5 seconds then went off as per the program below. Is that what I should type, DEC:1-9 or should it work on just sending '3'


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

MYVAR VAR BYTE

MAIN:
PAUSE 250
SERIN2 PORTC.5, 16780, [DEC MYVAR] '2400 INVERTED
IF MYVAR = 3 THEN HIGH PORTA.5
PAUSE 5000
low PORTA.5
GOTO MAIN

LEDave
- 11th April 2010, 23:53
That chip defaults to 4 MHz so you will want to add DEFINE OSC 4 to the beginning of your code.

That really did crack it you little star you.........!

The program works with just '3' being sent, fantastic.....!!!

Probably a good point to end for the weekend but what next? Transmit from the PIC to pc?

I've got to say, this is brilliant stuff. I've got to stop myself from wearing a whole in the carpet walking from one pc to the other to send '3' down the wire.

Once again mackrackit, many thanks for your time, effort and perseverance, really.

Dave

mackrackit
- 12th April 2010, 00:31
Probably a good point to end for the weekend but what next? Transmit from the PIC to pc?
Yup, Write code and set the hardware up so whatever you send to the PIC® echos bach to the PC.


I've got to say, this is brilliant stuff. I've got to stop myself from wearing a whole in the carpet walking from one pc to the other to send '3' down the wire.
:) Pretty soon you will be able to do things remotely.


Once again mackrackit, many thanks for your time, effort and perseverance, really.

No problem, I enjoy it when someone wants to learn.

LEDave
- 12th April 2010, 21:21
Hi mackrackit,

The serial data transfer is working a treat:)

Before we move on a couple of quick questions I'm a little confused on.

1/ 16780. This is the MODE for inverted 2400 baud right?

2/ The 'inverted' baud. Is that just keeping the transmit voltage level from pc - PIC at TTL levels 0 and +5v, instead of + or - 12v as used it RS232?

Right then what's next (I've got a spare brown wire here just itching to send something out of my PIC):D

LEDave
- 12th April 2010, 22:05
Would this work to send '4' out on PORTC.3 when '3' comes in from the pc.


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

MYVAR VAR BYTE

DATA_OUT CON 4

MAIN:
PAUSE 250
SERIN2 PORTC.5, 16780, [DEC MYVAR] '2400 INVERTED
IF MYVAR = 3 THEN HIGH PORTA.5
PAUSE 5000
LOW PORTA.5
PAUSE 250
SEROUT2 PORTC.3, 16780, [DEC DATA_OUT]
PAUSE 5000
GOTO MAIN

mackrackit
- 13th April 2010, 00:01
1/ 16780. This is the MODE for inverted 2400 baud right?
Correct


2/ The 'inverted' baud. Is that just keeping the transmit voltage level from pc - PIC at TTL levels 0 and +5v, instead of + or - 12v as used it RS232?
Nope, inverted means 1 is 0 and 0 is 1.
It is still 0 to +5.

What I can see of your code on my phone it looks like it should work.

LEDave
- 13th April 2010, 00:26
What I can see of your code on my phone it looks like it should work.

And you were right mackrackit:)

'3' came in from the pc and '4' arrived on the pc, brilliant!

Where to next? send some text?

Dave

mackrackit
- 13th April 2010, 05:05
You can send some text.

And.....

Now would be a good time to play with the SERIN2/SEROUT2 modifiers.
Data can be formatted several ways, HEX, BIN, DEC, ASC||, STRings...

Might be something sorta fun... Send a number to the PIC® say in DECimal format and have the PIC® return the number in other formats. Play with every combination you can think of. This should give you an understanding how different number systems work with this system.

Could even send a couple of numbers and have an operation done on them and the results sent back to the PC.

LEDave
- 13th April 2010, 11:20
I'm on it.

Could take a day or two (or three) though. One or two 'holes' to plug in LEDave's knowledge base, bear with me.

As an aside here, is it just me or is there something 'magical' 'mystical' even about all this? You've a little black 'spider' with 14 legs and three wires attached and numbers appearing on a monitor at the press of a button, I love it.

Must dash, work, work, work and a lot of reading to do.

Dave

mackrackit
- 13th April 2010, 18:19
As an aside here, is it just me or is there something 'magical' 'mystical' even about all this? You've a little black 'spider' with 14 legs and three wires attached and numbers appearing on a monitor at the press of a button, I love it.

Kind of like science fiction.

LEDave
- 13th April 2010, 19:56
Kind of like science fiction.

Exactly,even stranger though!

Here's tonight's effort, it works up to DEC255 then ouputs a zero for 256 etc, which is larger than a BYTE I'm thinking.


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE OSC 4

MYVAR VAR BYTE

MAIN:
PAUSE 250
SERIN2 PORTC.5, 16780, [DEC MYVAR] 'MODE 16780 = 2400 BAUD INVERTED
IF MYVAR = MYVAR THEN HIGH PORTA.5 'LET'S YOU INPUT ANY NUMBER.
PAUSE 5000
low PORTA.5
pause 250
SEROUT2 PORTC.3, 16780, [HEX MYVAR, 10, 13] 'OUTPUT IN HEX 'MYVAR' 10=L_FEED 13=C_RETURN
pause 5000
GOTO MAIN

LEDave
- 13th April 2010, 20:58
From the second part of the brief:


Could even send a couple of numbers and have an operation done on them and the results sent back to the PC.

Hmm, a little stumped here. To my mind (after a lot of reading but obviously not enough!) when the first BYTE (number) arrives I need to send it to a memory location where it won't be overwritten when the second BYTE arrives.Then add the two together.

The only thing I've found so far that has a seperate address element is this (I think):


Label VAR Size[Number of elements]

I'm thinking: MYVAR VAR BYTE [1] which is two elements 0,1. then somehow add element 0 to element1.

Warm or way off?

Dave

LEDave
- 13th April 2010, 21:15
Now I'm thinking:


Label VAR Size[Number of elements]

Might be used to output a block of data....Mmm..

A little more research me thinks.

Dave

mackrackit
- 13th April 2010, 23:25
it works up to DEC255 then ouputs a zero for 256 etc, which is larger than a BYTE I'm thinking.
Yup, remember when counting not to start at 1 like we were taught in school.
Always start at the origin... ZERO



Hmm, a little stumped here. To my mind (after a lot of reading but obviously not enough!) when the first BYTE (number) arrives I need to send it to a memory location where it won't be overwritten when the second BYTE arrives.Then add the two together.

The only thing I've found so far that has a seperate address element is this (I think):

I was thinking along the lines of something like this for now


NUM1 VAR BYTE
NUM2 VAR BYTE


I was saving ARRAYs for a little latter


I'm thinking: MYVAR VAR BYTE [1] which is two elements 0,1. then somehow add element 0 to element1.

But if you want to read ahead... :)
http://www.picbasic.co.uk/forum/showthread.php?t=544

LEDave
- 13th April 2010, 23:47
Hi mackrackit


But if you want to read ahead...

I'm with you, reading ahead is ok but learn to walk then run (or crawl then walk in my case).

Just out of interest would the ARRAY idea have worked?

This code is just an idea, is it on the right lines?


SERIN2 PORTC.5, 16780, [DEC NUM1] 'MODE 16780 = 2400 BAUD INVERTED

SERIN2 PORTC.5, 16780, [DEC NUM2] 'MODE 16780 = 2400 BAUD INVERTED

LET TOTAL = NUM1 + NUM2

SEROUT2 PORTC.3 TOTAL

mackrackit
- 14th April 2010, 00:37
An array can be made to work and so could your code as it is written, but...

One of the things you need to consider is, how is the data coming into the MCU?
123
1,2,3
12,3
12M3
...........
The code on the MCU needs to know what to expect or it is not going to know what to do with the data.
That is where arrays come in handy, but then you need to figure out what and where the data you want to use is located in the array.

I know, not a direct answer :)
Reread the section of the manual SERIN2 and the WAIT thing. Also find out what DEC2 or DEC3 does.

LEDave
- 14th April 2010, 00:57
I've been trying to use WAIT. I put in ( 2 ) hoping it would let me enter two numbers but it wouldn't compile (syntax error)


WAIT ( ) Wait for sequence of characters


Reread the section of the manual SERIN2 and the WAIT thing. Also find out what DEC2 or DEC3 does.

Will do, tomorrows task:)

LEDave
- 14th April 2010, 14:02
Hi mackrackit,

How does this look? It works but is it what you were after?


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE OSC 4

NUM1 VAR BYTE

NUM2 VAR BYTE

TOTAL VAR BYTE

i var byte

MAIN:
PAUSE 250

SERIN2 PORTC.5, 16780,[WAIT ("N1="), DEC NUM1] 'MODE 16780 = 2400 BAUD INVERTED
PAUSE 2000
HIGH PORTA.5
PAUSE 2000
LOW PORTA.5
SERIN2 PORTC.5, 16780,[WAIT ("N2="), DEC NUM2]

HIGH PORTA.5
LET TOTAL = NUM1 + NUM2
PAUSE 2000
low PORTA.5
pause 250
SEROUT2 PORTC.3, 16780, [DEC TOTAL, 10, 13] 'OUTPUT IN DEC 'TOTAL' 10=L_FEED 13=C_RETURN
pause 2000
GOTO MAIN

Dave

mackrackit
- 14th April 2010, 14:31
How does this look? It works but is it what you were after?

COOL!!!
I was not really after anything exactly, just trying to give you enough information to figure it out and you did!!!

Now try sending sending 123 with out N1= or N2=.


SERIN2 PORTC.5, 16780,[DEC NUM1, DEC NUM2]

Then try


SERIN2 PORTC.5, 16780,[DEC2 NUM1, DEC NUM2]

Then try


SERIN2 PORTC.5, 16780,[DEC NUM1, DEC2 NUM2]

Then try
Something else....
You will also want to look at the TIME OUT option of SERIN2.

LEDave
- 14th April 2010, 14:54
[WAIT ("N1=")

This took me ages to figure out:( But hey, got there in the end:)

I've also had a little play with DEC, DEC1.... late last night.

From what I've found, I think I'm right in saying 'DEC' is good up to 255 NUM1 VAR BYTE, send 256 and it returns a '0'.

'DEC1' is good 0 - 9 if you sent '23' then you'd only get a '2'

'DEC4' If you'd sent '99' you'd get '0099', '255' would give '0255' & 256 would return '0000'........ETC.

I'll have a look at the combinations you've posted this evening.

I know progress is slow but we're making progress:)

See you later.

Dave

mackrackit
- 14th April 2010, 15:57
This took me ages to figure out But hey, got there in the end

You are doing great. It does take some time to learn how to think this way.

DEC does determin the "size" but not as you think.
DEC is for how many digits to grab.
If 123 is sent and the receiving end is DEC2 the info gathered will be 12. The first two decimal places.

Looks like you are getting VARIABLE size confused with this.

The manual talks about this...
BIT = 0 to 1
BYTE = 0 to 255
WORD = 0 to 65535

In Binary a BIT will represent one place (_)
BYTE will represent eight places (_ _ _ _ _ _ _ _)
WORD will represent sixteen places (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)

8 BITs in a BYTE
2 BYTEs in a WORD

LEDave
- 14th April 2010, 21:00
Hi mackrackit,

I run those number variations / combinations, what a difference:


SERIN2 PORTC.5, 16780,[DEC NUM1, DEC NUM2]

This one grabbed 123 then added 123 to give 246.


[DEC2 NUM1, DEC NUM2]

This one grabbed the 1 and the 2 to give twelve, then added the 3 to give 15.


[DEC NUM1, DEC2 NUM2]

This grabbed 123 + 12 to give 135

Like you said earlier:


One of the things you need to consider is, how is the data coming into the MCU?

I can see this is very important, you've got to be comparing apples with apples, or else you're in real trouble, or at least be aware of how the numbers will be affected, your term 'grabbed' was right on the money.


Looks like you are getting VARIABLE size confused with this.

Guilty, I do tend to look at things one dimentionally before moving around and taking another view of things. It's that old lack of knowledge thing again:(

Ah just remembered, in the PICBASIC PRO book, the DB9 cable dia has a 22k series resistor on PIN3, do I need to add one or am I ok you think? (I can't smell any smoke:))

Where to next......?

Dave

mackrackit
- 14th April 2010, 23:41
Probably a good idea to use the resistor, on both pins 2 and 3.

Next... Some flow control.
What happens if you do not send data? _____________
There is a TIME OUT/ LABEL thing that goes with SERIN2 just for that.

Write a sub routine to indicate that data has not been received. Make it short, could be missing data while in the sub routine.

LEDave
- 15th April 2010, 00:56
Mmm, interesting.....!

More reading / GQQGLING for me.

Quick question, we set the mode to 16780 (2400 baud inverted). Does this in tern automatically set the FlowPin to the correct enabled state? 'This enabled state is determined by the polarity of the data specified by mode' (from the manual).

Also what's a reasonable 'Timeout' period in milliseconds for this?

I'll pick up a couple of resistors in the morning.

See you tomorrow.

Dave

mackrackit
- 15th April 2010, 07:12
Yes, the FLOW PIN is automatically taken care of if used, but we do not need it for what we are doing. It is an option only.


Also what's a reasonable 'Timeout' period in milliseconds for this?

That depends on the whole setup for what you intend to do. For these test with keyboard/PC entry 500+ might be a good place to start. If you are connected to something like a GPS that continuously sends data and depending on what else the program does 100 may be what works.

LEDave
- 15th April 2010, 12:29
Quick question. What happens to the value of TOTAL at it's memory location after it's sent serially?
Does the memory location automatically get reset to zero or does the value TOTAL stay there until over-written
by the next TOTAL value to be sent?


SEROUT2 PORTC.3, 16780, [DEC TOTAL, 10, 13]

Dave

mackrackit
- 15th April 2010, 13:00
It stays until over-written or power down.

LEDave
- 15th April 2010, 15:32
Hi mackrackit,

I expect you can hear the cogs grinding from where you are today;)

Here's what I'm thinking:


Timeout con 500

MAIN:
PAUSE 250

SERIN2 PORTC.5, 16780, [WAIT ("#"),DEC NUM1,Timeout,Data_Not_Sent,]

I've made Timeout a CONSTANT 500. Then the program goes to the LABEL Data_Not_Sent. This is were I'm struggling in that I need to be able to tell if the data has been sent. If TOTAL did reset to zero when data was sent I could have used that but it doesn't and it could have just sent to nought's so that would be no good for a handle anyway. Then I though I could 'read' the PIN PORTC.3 to see if that had changed state, again that's only 50-50 that it has from HO to Low and also it could have just sent two zero's which would show no change.

So I'm looking for something to show a change or changed state when data is sent (I think).

Am I hot or cold in that last assumption?

Dave

mackrackit
- 15th April 2010, 15:39
SERIN2 PORTC.5, 16780,Timeout,Data_Not_Sent,[WAIT ("#"),DEC NUM1]

The SERIN2 command looks for the change of state, when using RF the time out thing does not work very well because of noise. The state is always changing even if data is not being sent.

LEDave
- 15th April 2010, 20:24
The SERIN2 command looks for the change of state

So SERIN2 looks at SEROUT2 (PORTC.3) to see if data has been sent?

PORTC.3's pin state is the key to DATA_Not_Sent?

I'm either getting a lot warmer or a lot colder with that one.

mackrackit
- 15th April 2010, 20:29
North of the Arctic Circle on that one... :)

The time-out option looks for a state change on the serial input pin to see if data has been received on that pin.

LEDave
- 15th April 2010, 20:55
North of the Arctic Circle on that one...

Lol......!

It was a bit of a howler wan't it, oh dear.

LEDave
- 15th April 2010, 21:44
I've just re-read the brief mackrackit.


What happens if you do not send data?

I thought you meant from the PIC to the pc, that's why I kept going towards a change of state on SEROUT2 (PORTC.3).

I see what you're saying now (I still don't now the answer (yet)) at least I'm looking in the right area now (I think).

Dave

mackrackit
- 15th April 2010, 21:56
Yup, you are heading South now.
While I am on my way North with the gizmo I am playing with.

LEDave
- 15th April 2010, 22:06
Yup, you are heading South now. :D


While I am on my way North with the gizmo I am playing with.

I'm intrigued, what you working on then mackrackit

mackrackit
- 15th April 2010, 22:12
I got the bright idea that would figure this one out.
http://www.picbasic.co.uk/forum/showthread.php?t=12948

LEDave
- 15th April 2010, 22:39
Mmm,

I'm might be able to help you, in about 15 years....!

LEDave
- 16th April 2010, 13:37
Hi mackrackit,

I've got something that 'works'


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE OSC 4

NUM1 VAR BYTE

NUM2 VAR BYTE

TOTAL VAR BYTE

Timeout con 10000

MAIN:
PAUSE 250

SERIN2 PORTC.5, 16780,Timeout,Data_Not_Sent,[DEC NUM1, DEC2 NUM2]
PAUSE 6000
HIGH PORTA.5
PAUSE 1000
LOW PORTA.5

LET TOTAL = NUM1 + NUM2
PAUSE 250

SEROUT2 PORTC.3, 16780, [DEC TOTAL, 10]
pause 250

DATA_Not_sent:
High PORTA.1
PAUSE 75
LOW PORTA.1
GOTO MAIN

If I just load the program into the 16F684 and leave it running, every 10 secs PORTA.1 LED blinks as per the Timeout setting. I've given it a 10 secs delay because it takes about 4 secs to input two numbers into my clunky old keyboard.

You might be wondering why there's a six second delay after the NUM's are inputted, it's so I can visually see via the LED PORTA.5 that it has arrived (if that makes sense).

What do you think.

Dave

HenrikOlsson
- 16th April 2010, 13:44
That's great Dave, you're making a lot of progress!

What happens if you input 200 and 300 for num1 and num2 ? Why?

Next challenge, if mackrackit don't mind:
Make it so you actually input the complete equation, not only the two numbers. In other words 200+300 or 20-30 or 5*12 or....

/Henrik.

mackrackit
- 16th April 2010, 15:44
Looking good Dave!!!

Now you have Henrik's challenge. :)
Sounds like a good next step to me.

Henrik, I do not mind at all, the more teachers the better.

LEDave
- 16th April 2010, 16:56
That's great Dave, you're making a lot of progress!

Thanks to mackrackit and yourself I am:) When you think that in February I couldn't turn an LED on or even create a HEX file....!

Right then:


What happens if you input 200 and 300 for num1 and num2 ? Why?

Well the answer / output would be 230. Reason 200 is fine (BYTE = 255) the 300 which due to a mistake by me I set as D2 (DECIMAL2) in the program only takes the first two digits 30 so 200+30=230. How does that sound?


Make it so you actually input the complete equation, not only the two numbers. In other words 200+300 or 20-30 or 5*12 or....

Well the for first part 200+300 I'd have to set TOTAL VARIABLE BYTE to TOTAL VARIABLE WORD for the number 300 (that's assuming you can add a BYTE to a WORD.....Mmm, something makes me think this isn't going to be that straight forward......!

HenrikOlsson
- 16th April 2010, 17:30
Hi Dave,

You are correct, in your case it would be 230. (I missed that DEC2 you had in there).

What I was really going for was the fact that you have all three variables, Num1, Num2 and Total all declared as Bytes. So 200 in Num1, that's fine. But 300 in Num2 won't work as it will overflow and will actually result in the value 44 in Num2 the Total would be 244. Same thing if you'd do 200+200, Num1 is fine and so is Num2 but 400 won't fit in Total... You seem to have that under control though!

For the next exercise, why not make the PIC ask three questions like:

Num1: (You input whatever)
Operator: (You input +, - / or *)
Num2: (You input whatever)

And then present the result. That should make it a little easier to sort out - I think.

/Henrik.

LEDave
- 16th April 2010, 23:07
Hi Henrik


For the next exercise, why not make the PIC ask three questions like:Num1: (You input whatever) Operator: (You input +, - / or *) Num2: (You input whatever)

Just to clarify: When I turn the Serial Communicator on, the PIC will send a request to the Communicator for NUM1, when I send that number, the PIC then asks the Comunicator for an 'operator' + - */ when the operator arrives the PIC then asks for NUM2 and then present the result.


That should make it a little easier to sort out - I think. :eek:

I'll give it a go.

Dave

LEDave
- 17th April 2010, 00:20
Hi Guys

I think I need a pointer. How do I 'capture' an 'operator'?

When I want a DEC NUM1 sent I can see how [DEC NUM1] receives a decimal number. From the manual WAIT ( ) seems to be the best fit for an 'operator' or maybe something like CHAR " "

Here's a section of the program:


OP VAR BYTE
MAIN:
PAUSE 7000
SEROUT2 PORTC.3, 16780, ["Please send NUM1", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows request sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTC.5, 16780, [DEC NUM1]'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

PAUSE 250
SEROUT2 PORTC.3, 16780, ["Please send Operator + - * /"][WAIT OP( ),]
PAUSE 500
HIGH PORTA.5 'Shows request sent
PAUSE 1000
LOW PORTA.5


Here's were I'm struggling


SEROUT2 PORTC.3, 16780, ["Please send Operator + - * /"][WAIT OP( ),]

Dave

HenrikOlsson
- 17th April 2010, 08:31
Hi Dave,
The WAIT modifier is used with serial input commands not with the serial output commands. It's used to only start "capturing" data starting with a certain character(s).

Simply have your SERIN2 command capture the operator in a BYTE variable. Then, when you have Num2 as well you can use a bunch of IF-THENs to determine what the operator is, and act upon it accordingly OR even better, have a look at Select Case.


SERIN2 PORTC.5, 16780, [OP] 'MODE 16780 = 2400 BAUD INVERTED

Every character, A,B,C, +, -, * etc is represented as a single byte number. So all you need to do is something like:


IF OP = "+" Then
Total = Num1 + Num2
ENDIF
And so on.

Hope that helps.
/Henrik.

LEDave
- 17th April 2010, 11:01
Henrik thank you.

I was thinking in the right way (I had OP as a VAR BYTE) but just couldn't figure out how to receive and capture the operator.:(


OR even better, have a look at Select Case.

Will do.

The thing I'm finding the hardest by far at the moment is interpreting what everything actually means.I read a line from the manual, all seems clear then suddenly the wheels fall off! It's rather like doing a crossword puzzle in a foreign language for me right now, I guess you guys have all been through this though.

Practice, practice, practice.

Dave

LEDave
- 17th April 2010, 11:04
Breaking News.........

The LCD's have just arrived :)

Dave

LEDave
- 17th April 2010, 19:15
Hi Henrik,

How does this look? I went for the 'select case' in the end, I had to think for a while (nothing new there) but got there in the end.


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE OSC 4

NUM1 VAR BYTE

OP VAR BYTE

NUM2 VAR BYTE

TOTAL VAR BYTE



MAIN:
PAUSE 7000
SEROUT2 PORTC.3, 16780, ["Please send NUM1", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTC.5, 16780, [DEC NUM1]'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

PAUSE 250
SEROUT2 PORTC.3, 16780, ["Please send Operator + - * /", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTC.5, 16780, [OP] 'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

PAUSE 250
SEROUT2 PORTC.3, 16780, ["Please send NUM2", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTC.5, 16780, [DEC NUM2]'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

Select case OP
CASE "+"
TOTAL = NUM1 + NUM2
CASE "-"
TOTAL = NUM1 - NUM2
CASE "*"
TOTAL = NUM1 * NUM2
CASE "/"
TOTAL = NUM1 / NUM2
END SELECT

pause 250
SEROUT2 PORTC.3, 16780, [DEC TOTAL, 10,13]
PAUSE 250
GOTO MAIN

I did another version using IF-THEN as you showed me.


PAUSE 250
IF OP = "+" Then
Total = Num1 + Num2

PAUSE 250
IF OP = "+" Then
Total = Num1 + Num2
ENDIF

PAUSE 250
IF OP = "-" Then
Total = Num1 - Num2
ENDIF

PAUSE 250
IF OP = "*" Then
Total = Num1 * Num2
ENDIF

PAUSE 250
IF OP = "/" Then
Total = Num1 / Num2
ENDIF

mackrackit
- 17th April 2010, 20:10
Well that was easy....
We need to think of something harder :D

LEDave
- 17th April 2010, 20:57
Hi mackrackit


Well that was easy....

Only because you and Henrik are such good teachers....!


We need to think of something harder

Ok, but be gentle with me.

How about this:


Yup, Write code and set the hardware up so whatever you send to the PIC® echos bach to the PC

From an earlier brief.

Dave

HenrikOlsson
- 18th April 2010, 09:32
Looking good Dave! As you see the Select Case can provide a much cleaner look than the IF THEN in some cases. What you also can do is have a CASE ELSE where you "capture" invalid input (anything BUT + - / *).

You have a lot of Pauses in there that doesn't need to be there if there's no specific reason for it.

Now, since you have the LCD, why not make the messages appear on it instead of the PC-screen? You can still receive the "commands" thru the PC, to begin with.

LEDave
- 18th April 2010, 19:13
Hi Henrik,


Now, since you have the LCD, why not make the messages appear on it instead of the PC-screen? You can still receive the "commands" thru the PC, to begin with. :):)

That would be brilliant, I'm ready when you are!

I've uploaded the PDF for the LCD.

Quick point, on my PICkit1, I'm using two 22k resistors on the DB9 data cable (pin2&3) do I still use these for the LCD?

Dave

mackrackit
- 18th April 2010, 19:23
Hey Dave,
I will but back in....

Check out the LCD section of the manual and compare to the LCD data sheet for the pin outs. Make needed adjustments and....

LEDave
- 18th April 2010, 23:18
Make needed adjustments and....

I'm not sure how much of the display I need to connect up?

How does this look / sound:

PIN1 - VSS - GND
PIN2 - VDD - +5V
PIN3 - V0 - 20k pot (contrast)
PIN4 - RegSel - PORTA.4? with 10k pull res.
PIN5 - ReadWrite - GND
PIN6 - PORTB.3?

PIN11 - D4 - I/O - Data LSB - PORTA.0?
PIN12 - D5 - I/O - Data - PORTA.1?
PIN13 - D6 - I/O - Data - PORTA.2?
PIN14 - D7 - I/O - Data MSB - PORTA.3?

The manual qoutes for a PIC16F84 I'm using a 16F684, don't forget, hence the question marks.
I'm thinking it still applies the same though.

Dave

HenrikOlsson
- 19th April 2010, 06:12
Hi Dave,
That looks OK to me. Don't forget that if your pin assignment differs from the "standard" shown in the manual (I haven't checked but I think yours is different) you need to DEFINE that as shown in the manual. Simply copy the complete DEFINE-block to your code and change it to match your setup.

/Henrik.

LEDave
- 19th April 2010, 17:17
Hi Henrik

I've bought a breadboard today and have decided to make the project on it.
So starting from scratch really.

Yes the code does need adjusting to match the manual (probably the best way around at this stage) so lots to do and think about.

If this LCD ever fires up and works it'll be a minor, no major miracle!

Dave

LEDave
- 19th April 2010, 23:20
Not having a very good night here. I've been working realy hard with zero results so far.

I've attached wires 1-6 on to the LCD - power supply - and PIC (the PIC hasn't been DEFINED yet) but the LCD display hasn't shown any sign of life at all (I was just hoping the display would at least light up).

My only hope is that the PIC has to have the right DEFINE's in place even to light up, fingers x'd that's the case, or NASA I've got a problem:(

Dave

mackrackit
- 19th April 2010, 23:30
I would not expect much till it is all connected and coded.
Do you have a POT on he contrast pin?

Still having trouble after all is connected post the connections, code, and trouble having.
Do not forget to turn off the ADC...

LEDave
- 19th April 2010, 23:35
Hi mackrackit,

Yes there is a pot on the contrast pin, the manual said 20k best I could buy today was a 25k (I turned the pot just in case it was 'dark') the display never lit up though.

So I need to get the right program settings into the PIC before it will even light up then? That's a good thing, because there's still hope!

I'll have a try at getting the program set up tomorrow and see what you and Henrik think. There aren't any DEFINES at all inside the PIC at the moment (might just explain it I guess).

Dave

HenrikOlsson
- 20th April 2010, 06:18
Hi Dave,
I went over your suggested connection scheme again and it looks OK. I would expect the LCD segments to at least be visible with the contrast pot is turned towards one end - that's what I've seen on other displays. But don't worry, get it all connected and get some basic code into the PIC.

I'm not 100% sure if the LCDOut commands automatically sets the TRIS registers for the Enable and RS bit of the LCD but it certanly doesn't hurt to do that "manually" just to be sure it's correct. And, as mackrackit already pointed out, don't forget the ADC.

I think these DEFINEs should match your connection scheme:


DEFINE LCD_DREG PORTA 'Databus, D4-D7 on PortA
DEFINE LCD_DBIT 0 'Starting at PortA.0

DEFINE LCD_RSREG PORTA 'LCD RegisterSelect on PortA...
DEFINE LCD_RSBIT 4 '...bit4

DEFINE LCD_EREG PORTB 'LCD Enable-signal on PortB...
DEFINE LCD_EBIT 3 '...bit 3

DEFINE LCD_LINES 2 'LCD has two lines and...
DEFINE LCD_BITS 4 '...is using 4 bit databus

DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
/Henrik.

LEDave
- 20th April 2010, 08:08
.....................

LEDave
- 20th April 2010, 08:47
Hi Henrik

Here's what I'd come up with late last night (I wish I'd posted it now before I went to bed as not the far off I don't think).



DEFINE LCD_DREG PORT.A ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORT.A ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTC ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 4 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50


I set LCD_LINES 4 as the display is a 4*20.

The one I'm missed was LCD_EBIT 0 (it was late).

Also the PIC is a 16F684 PORTA and PORTC

Thank you for taking the time to do go through it all though (really appreciated) I'll load it later today and hopefully have some success (I'm just a little worried I've fried the LCD).

David

HenrikOlsson
- 20th April 2010, 09:37
Hi Dave,
Ah, OK - I never crosschecked with the PIC datasheet, I only referenced your proposed connection scheme and LCD datasheet. So, PORTA and PORTC it is.

One thing though, there's not supposed to be dot in PORT.A it's just PORTA. The thing with DEFINEs is that they won't produce any error messages etc so you have to make sure you write them correctly or it simply won't work properly.

mackrackit
- 20th April 2010, 12:27
PORTA.3 is input only so you will need to move this over to portC.

mackrackit
- 20th April 2010, 12:50
How about doing it like this. The whole thing will be on PORTC. That will keep away from the MCLR and programming and POT(if still using the PICKIT1) pins.


DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
LCD pins
1 and 5 to VSS
2 to VDD
3 to wiper on POT

LEDave
- 20th April 2010, 17:39
Hi mackrackit,

I've moved the whole thing over to the breadboard and wired it on there.

A couple of quick things:

Yes the manual shows a 10k res on MCLR, I've put one on PORTA.3 which probably isn't a good idea.

I've checked the voltage on the display itself earlier:

Across pin 1-2 = 4v (with pin 1 as GND)
Across pin 1-3 = it goes from 0 - 3.94v
Across pin 2-5 = 3.92v

Also (I've just noticed this) when I turn the POT, the top and third line of the display get darker, so something's going on or trying to.

mackrackit
- 20th April 2010, 17:49
I would turn MCLR off then you can use that pin as an input.

Display sounds like it is alive :)

LEDave
- 20th April 2010, 18:10
To do that I add: @ DEVICE PICI6F684, MCLR_OFF (just checking).

Display sounds like it is alive. It does yes:)

I was hoping for a nice vivid blue but right now I'l take the slate grey through to black:o

Byte_Butcher
- 20th April 2010, 18:20
You may not see the blue color until the backlight is powered up.


steve

mackrackit
- 20th April 2010, 19:02
To do that I add: @ DEVICE PICI6F684, MCLR_OFF (just checking).


That would do it.
Not sure if we have talked about configs yet?
How are you setting them?

LEDave
- 20th April 2010, 19:31
Hi mackrackit,

No we haven't touched on them yet (CONFIGS). I have read a little about them, If I'm honest though at this stage or up to now if the programs compiled and run great.

We will have to cover them soon though.

A few jobs around the house then back on the display! It will work, I know it will (I think).

Dave

LEDave
- 20th April 2010, 23:49
UPDATE:

I think the cct is wired up somewhere handy (non technical term). I was a bit unlucky in that I bought a ribbon cable for the job which had the finest wire inside I've ever seen, so had to solder some stiffer 'legs' on to all the wires which kept breaking off, grrr.

The LCD still shows the same 2 dark lines when the pot is turned.

I went for your PORTC option in the end mackrackit (@ DEVICE PICI6F684, MCLR_OFF wouldn't compile for one).

One thing, as Henrik said earlier:

I'm not 100% sure if the LCDOut commands automatically sets the TRIS registers for the Enable and RS bit of the LCD but it certanly doesn't hurt to do that "manually" just to be sure it's correct.

Right now I'm not sure what to set the TRIS registers to for this.

The only other thing I know I haven't done is transfer the GROUND - PIN2 - PIN2 from the PICKit1 (serin / out) to the LCD display.

Ok, here's the program as it stands:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

DEFINE OSC 4

NUM1 VAR BYTE
OP VAR BYTE
NUM2 VAR BYTE
TOTAL VAR BYTE

MAIN:
PAUSE 7000
SEROUT2 PORTA.0, 16780, ["Please send NUM1", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTA.2, 16780, [DEC NUM1]'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

PAUSE 250
SEROUT2 PORTA.0, 16780, ["Please send Operator + - * /", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTA.2, 16780, [OP] 'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

PAUSE 250
SEROUT2 PORTA.0, 16780, ["Please send NUM2", 10, 13]
PAUSE 500
HIGH PORTA.5 'Shows data sent
PAUSE 1000
LOW PORTA.5

PAUSE 250
SERIN2 PORTA.2, 16780, [DEC NUM2]'MODE 16780 = 2400 BAUD INVERTED
PAUSE 500
HIGH PORTA.5 'Shows data arrived
PAUSE 1000
LOW PORTA.5

Select case OP
CASE "+"
TOTAL = NUM1 + NUM2
CASE "-"
TOTAL = NUM1 - NUM2
CASE "*"
TOTAL = NUM1 * NUM2
CASE "/"
TOTAL = NUM1 / NUM2
END SELECT

pause 250
SEROUT2 PORTA.0, 16780, [DEC TOTAL, 10,13]
PAUSE 250
GOTO MAIN

LEDave
- 21st April 2010, 00:22
I've just transfered the GROUND - PIN2 - PIN3 from the PICKit1 (serin / out) to the PIC / LCD display.The program works on the pc serial communicator as before but doesn't show anything up on the LCD which is a shame.


Dave

mackrackit
- 21st April 2010, 00:44
Maybe you should put something in your code to send data to the LCD??


LCDOUT $FE,1,"Hello World!"

LEDave
- 21st April 2010, 01:17
LCDOUT $FE,1,"Hello mackrackit"

It WORKED!!!!!!!!!!!!!!!

Fantastic, what a buzz!

Right I'm to bed now it's really late, really pleased with that:):):)

Thanks for your help everyone.

Dave

LEDave
- 21st April 2010, 09:10
The display's looking good:)

I guess I should do some reading on LCD characters '$FE,1,' etc and figure out how they work.

Absolutely brilliant to see it actually come to life late last night.

Thanks again to everyone.

David

mackrackit
- 21st April 2010, 11:45
To have a little fun check this out
http://www.picbasic.co.uk/forum/showthread.php?t=242

LEDave
- 21st April 2010, 14:18
Hi mackrackit,

I'll have a look when I get the display running properly. I've got a slight problem at the moment:

Lines 1 & 3 are fine. Line 2, the top half of the characters are fine and I can make out the bottom half. Line 4 top half fine, bottom half of the characters is missing.

It seems like a contrast issue on the pot. If I could only turn the pot down another quarter turn but I've run out of pot.

Would getting the back-light fired up help do you think?

Dave

mackrackit
- 21st April 2010, 17:01
You might try increasing the DATAUS number.

LEDave
- 21st April 2010, 22:25
Have tweaked the DATAUS and can see pretty much all the characters, cheers.

I'm slightly embarrassed but I'll fess-up. I'm still having a problem with the back-light.

The display pdf shows the Anode / cathode on pins 15 / 16 with the current as below:


With B/L ILED VLED=5.0V -- 72 80 mA

So I'm thinking at 5v with 75ma a 60 ohm resistor on pin 15, pin 16 ground should do it.

I always thought LED's worked on about 25ma, must be a big LED inside then?

Dave

Byte_Butcher
- 21st April 2010, 22:41
So I'm thinking at 5v with 75ma a 60 ohm resistor on pin 15, pin 16 ground should do it.

I always thought LED's worked on about 25ma, must be a big LED inside then?

Dave

It may have one big LED, or several smaller ones in parallel.
I have some Lumex displays that are rated for up to 160mA. But they are viciously bright at that level and I rarely run them at more than 50mA.
For dim lighting conditions, I may run them at 20mA..

I'd start with about 1/2 current and see how it goes. No need to run them any harder than necessary. If you've got 100 ohms, or 200 even, give it a go.

Don't forget that resistor wattage... a 60 ohm resistor @ 75mA = 0.3375 watts dissipated.

Steve

LEDave
- 21st April 2010, 23:24
Thanks for that Steve.

I'll start with 200ohms. Just to double check that goes to the anode pin 15 right?

Dave (Mr Windy).

mackrackit
- 21st April 2010, 23:39
It does not matter, 15 or 16.

LEDave
- 22nd April 2010, 16:52
Finaly managed to find five minutes to connect the back-light up using a 150ohm
resistor, however:

Before connection I had 4 lines of text. Then I connected the back-light which came on a nice blue colour but the text vanished. I then disconnected the back-light,the text didn't reappear, reloaded the program still no text (with or without the back-light on). I then loaded the program into my other 16F684 with the same outcome:(

Could it be the DATAUS number again?

Or something more worrying.

Dave

HenrikOlsson
- 22nd April 2010, 17:39
Hmmm, from where do you pull the current for the backlight and is that supply rated/capable of supplying the current? Measure the voltage as you turn on the backlight and see if it sags.

Do you have a PAUSE at the beginning of the program to allow the LCD to boot up properly before writing to it? Something like PAUSE 1000 or whatever....

/Henrik.

LEDave
- 22nd April 2010, 18:02
Hi Henrik

I've measured the voltage, it doesn't blip from 4.6v, even when the back-light is switched off - on.

I added the pause.Still no text showing.

Here's the program:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 75

DEFINE OSC 4

MAIN:
PAUSE 1500
LCDOUT $FE,1,"*Hello WORLD*!"
LCDOUT $FE,$C0,"I't WORKS!"
LCDOUT $FE,$94,"I't WORKS!"
LCDOUT $FE,$d4,"Oh dear it stopped!"
GOTO MAIN

Dave

HenrikOlsson
- 22nd April 2010, 18:45
Hi Dave,
Try adding a LED to an unused pin and blink it a few times at start-up. Just to verify that the PIC is still actually executing code. Are you using an extarnal crystal or are you running on the internal oscillator?

If it appears to not executing code and you're using an external source for the osciallator then check and double check that.

/Henrik.

LEDave
- 22nd April 2010, 19:11
Hi Henrik,


Try adding a LED to an unused pin and blink it a few times at start-up. Just to verify that the PIC is still actually executing code.

Will do.


Are you using an extarnal crystal or are you running on the internal oscillator?

Internal oscillator.

It does seem strange that the PIC wrote the test lines to the LCD then stopped when the back-light was fired up. It would be nice if it were something not too serious.

Dave

LEDave
- 22nd April 2010, 19:30
Hi Henrik,

I've added the LED and pause to the program and no (unless I've made another mistake) the LED doesn't blink,so program not / stopped running? Program doesn't 'run' with the back-light turned off either.

Here's the code:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 75

DEFINE OSC 4

MAIN:
PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
PAUSE 1500
LCDOUT $FE,1,"*Hello WORLD*!"
LCDOUT $FE,$C0,"I't WORKS!"
LCDOUT $FE,$94,"I't WORKS!"
LCDOUT $FE,$d4,"Oh dear it stopped!"
PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
PAUSE 50
GOTO MAIN

Dave

LEDave
- 22nd April 2010, 20:17
Well I changed the LCD_DATAUS n from 75 to 150 and the led fired up on PORTA.5, still no text on the LCD though.

Dave

mackrackit
- 22nd April 2010, 21:06
I would not think DATUS would cause the LED not to work...
Have you adjusted the contrast POT after connecting the back light? Maybe it is just washed out ?

LEDave
- 22nd April 2010, 21:14
Hi mackrackit,


Have you adjusted the contrast POT after connecting the back light? Maybe it is just washed out ?

Yes, I've even disconnected the back light but can't see any text now, it hasn't reappeared.

Dave

LEDave
- 22nd April 2010, 21:23
I've cracked it...........!!!.....Yippeee.

PIN 5 onto LCD from PIC loose R/W.

Henrik, mackrackit, really sorry to have caused a problem.

The display looks great, bright but not too bright and the text is as clear as clear.
:):):)Dave

mackrackit
- 22nd April 2010, 22:07
If I only had a dime for everytime something like that has happened to me :)

LEDave
- 22nd April 2010, 22:35
If I only had a dime for everytime something like that has happened to me :)

I don't think it'll be my last either...;)

Really pleased it's going though.

So a good place to start and get a grip / understanding of LCD display characters would be that link you posted earlier:


http://www.picbasic.co.uk/forum/showthread.php?t=242

Interfacing an LCD with a project opens up so many possibilities, be it just instructions right through to displaying live information. I suspect it's not going to be easy but I'd like to get a grip on LCD's: They're seriously...:cool:

Dave

mackrackit
- 22nd April 2010, 23:13
Yes, that link will show you how to do custom characters.
You will also want to look in the manual about how to place a normal character anyplace on the display along with different things that can be done with the cursor.

LEDave
- 22nd April 2010, 23:32
I'm on it....

See you tomorrow.

Dave

LEDave
- 23rd April 2010, 21:44
I had a go at loading a couple of custom characters with no success, so I thought I'd make my name move across the screen. Here's a part of the program.

The trouble is, on the third line down of the LCD (first square) my name also appears there. Could I when trying to load a custom character have inadvertently done something to the CGRAM setting? I then thought maybe it's the cursor so I turned that off with no joy, name moves across the screen still and also 1'st square third line.


MAIN:
pause 1000
LCDOUT $FE,$0C 'Cursor off
PAUSE 50
LCDOUT $FE,1," *"
pause 500
LCDOUT $FE,1," *D"
pause 500
LCDOUT $FE,1," *DA"
PAUSE 500
LCDOUT $FE,1," *DAV"
PAUSE 500
LCDOUT $FE,1," *DAVE"

Nice work on the website by the way.

Dave

mackrackit
- 23rd April 2010, 21:58
Part of the problem might be the 21 spaces on a 20 character screen??

Post you custom character code and we will see whats up.

LEDave
- 23rd April 2010, 22:32
Hi mackrackit,

Oh dear, I can't even count up to 20 now:(

I've been working on my HEX today, maybe that explains it:eek:

Working a treat now thanks, 'again'.


Post you custom character code and we will see whats up.

It's not mine it's Darrel Taylor's, from that link you posted. It's the battery symbol.


MAIN:
PAUSE 500
LCDOUT $FE,$78,$06,$0f,$0f,$0f,$0f,$0f,$0f,$00
GOTO MAIN

Dave

mackrackit
- 23rd April 2010, 23:16
The LCDOUT character stuff place at the beginning of your code, in the variable area.


LCDOUT $FE,$40,$06,$0f,$0f,$0f,$0f,$0f,$0f,$00 'This is the first character #0
'The first place in the RAM is $40
'The next character would start with $48
VARS
DEFINES
...
Then in your loop


MAIN:
PAUSE 500
LCDOUT $FE,1,0 'First character
LCDOUT $FE,1,1 'Second character if you have one
GOTO MAIN

LEDave
- 23rd April 2010, 23:34
Cheers mackrackit,

Things slowly starting to filter through. I'll have a look tomorrow.

I love the old LCD though, cracking.

Dvae

LEDave
- 25th April 2010, 20:01
Hi mackrackit,

Well I managed to get the program to do what I wanted it to do, namely run through four custom characters then place the four custom characters one in each corner of the display ( program code below).

All the info to do this was found within the LCD link you posted:) However, I can't really see how the CONSTANT:
Row1 CON 128 works, what does the 128 part of it mean? I guess it must relate to LCD position HEX 0000 DDRAM Address for a 4 Line LCD but can't relate that to a CGRAM character position.


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 150

Row1 CON 128
Row2 CON 192
Row3 CON 148
Row4 CON 212

DEFINE OSC 4
LCDOUT $FE,$40,$02,$06,$1a,$1a,$1a,$06,$02,$00 'FIRST CHAR 0 (Battery)
LCDOUT $FE,$48,$06,$0f,$0f,$0f,$0f,$0f,$0f,$00 'Second CHAR 1 (Speaker)
lcdout $FE,$50,$1F,$11,$15,$17,$17,$15,$11,$1F 'Third CHAR 2 (Copywrite)
lcdout $FE,$58,$00,$0a,$0a,$00,$00,$11,$0e,$00 'Fourth CHAR 3 (Smiley)
MAIN:
PAUSE 500
LCDOUT $FE,1,0 'First character
pause 1000
LCDOUT $FE,1,1 'Second character
pause 1000
lcdout $FE,1,2 'Third character
PAUSE 1000
lcdout $fe,1,3 'Fourth Character
pause 1000
LCDOUT $FE,Row1+0,0 'Places CHAR 0 Top LHS of display.
PAUSE 250
lcdout $FE,ROW1+19,1 'Places CHAR 1 Top RHS of display.
PAUSE 250
LCDOUT $FE,Row4+0,2 'Places CHAR 2 Bottom LHS of display.
PAUSE 250
LCDOUT $FE,Row4+19,3 'Places CHAR 3 Bottom RHS of display.
PAUSE 4000
GOTO MAIN


Dave (lovin his LCD).

mackrackit
- 25th April 2010, 20:42
Each position on the display has a number for an "address".


Row1 CON 128 = $80
Row2 CON 192 = $C0
Row3 CON 148 = $90
Row4 CON 212 = $D0
'All first position on each of the lines
By adding to the constant you can place the character anyplace you want on the display.
First line third position from the left would be
$83 or 131

Setup a loop adding to the constant and see if you can make something scroll.

LEDave
- 25th April 2010, 21:48
Ah right (penny drops):) cheers mackrackit.



Setup a loop adding to the constant and see if you can make something scroll.

Mmm, I'll see what I can do.

Dave

LEDave
- 26th April 2010, 21:42
I'm still working hard on this........!

I know what I need to do to get this to work (on paper as it were, I think I do anyway:eek:). I'm reading and GQQGLing like made to find and learn the programming skill I need to make it work.

If I can't crack it tonight I'll have to ask, tick, tick, tick....must dash.

Dave

LEDave
- 27th April 2010, 00:09
Well I did try.......:(

It was getting the LCD to output B0 as a DEC number (LCD location for the smiley) rather than just B0 that foxed me. I tried DEC B0 and a few other things ("."B0..."B0") but still no good. I think (and hope) I was on the right lines though.

Here's my attempt:


BO VAR BYTE 'BYTE 0 Sets position for CHAR 128...+19
LC var byte 'Loop_Count Counts 0 to 19 'positions' across display

LCDOut $FE,$60,$00,$0a,$0a,$00,$00,$11,$0e,$00 'Smiley Face

Pause 500
MAIN
For LC = 0 TO 19
PAUSE 500
LET BO = 128 + LC 'Start at LCD Top LHS then add 1 to move across display
LCDOUT $FE,1,B0,0 'Output the 'Smiley Face' at location B0
PAUSE 500
Next LC
GOTO MAIN


Dave

mackrackit
- 27th April 2010, 00:37
Reallllllly close :)
Made a couple smal changes


LCDOut $FE,$40,$00,$0a,$0a,$00,$00,$11,$0e,$00 'Smiley Face
For LC = 0 TO 19
PAUSE 500
LET BO = 128 + LC 'Start at LCD Top LHS then add 1 to move across display
LCDOUT $FE,1
LCDOUT $FE,BO,0 'Output the 'Smiley Face' at location B0
PAUSE 500
Next LC
GOTO MAIN
But there is still one small problem...
I will leave that for you :D

LEDave
- 27th April 2010, 14:04
Well I compiled it and it ran........:) Like you say I wasn't a million miles off on this one which is pleasing.


But there is still one small problem...

Mmm, I've looked and looked and I can't see one. Was it from the original brief where you said use a CONSTANT and I've used a VARIABLE?

Quick question. In the program you made the change of address from $60 to $40, that's because the Custom characters are given memory addresses $40.....$78 (Char 0 - 7) and they must be sequential right? In other words I had Character '0' at address $60 which was a mistake.

Also having the:


LCDOUT $FE,1

Simply clears the display on every loop so the next increment of LC moves the character along one and clears the previous character.

Dave (Oop's what's next?)

mackrackit
- 27th April 2010, 14:25
Mmm, I've looked and looked and I can't see one. Was it from the original brief where you said use a CONSTANT and I've used a VARIABLE?
OOPPSS! Now I am the one that can not count. I have a 16x4 I use for testing. It would work for you 20x4 display.


Quick question. In the program you made the change of address from $60 to $40, that's because the Custom characters are given memory addresses $40.....$78 (Char 0 - 7) and they must be sequential right? In other words I had Character '0' at address $60 which was a mistake.Yes, your were calling the wrong address.


Simply clears the display on every loop so the next increment of LC moves the character along one and clears the previous character.
LCDOUT $FE,1Can not have a character location after it, only display commands. But for spped you can do this, (a snippet from,,)


LCDOUT $FE,1,"THE TEMPERATURE",$FE,$C0,"IS: ",DEC TRESULT,$FE,$90,"BAD READS ",DEC BCS
Dave (Oop's what's next?)I will get back to you with something :D

LEDave
- 27th April 2010, 15:24
Thanks for that mackrackit, a great help.


I will get back to you with something

As and when mackrackit, we're all busy.:)

Dave

mackrackit
- 27th April 2010, 15:50
Had to look over what we have done so far.
Serial
LCD
Some program flow.
Input from a switch

How about remembering something?
Let's say you have some parts moving along a conveyor and you want to count how many parts have passed by a certain point. But the problem is when the machine is turned off and then turned back on the counting starts back at zero and you want total parts counted for a week.

You can use the push button to simulate when a part passes by and have a WORD size variable increment each time the switch is activated and that value displayed someplace (serial or LCD).

To save the value for when the machine is turned off and on you will need to save the value to EEPROM and read from the EEPROM when the machine is started again. Place that value into the counting variable to continue counting from where it left off.

Another problem that can be addressed later is the EEPROM only has 1,000,000 write cycles so if the EEPROM is written to each time a part passes depending on how fast things are moving you could wear out the EEPROM in a matter of weeks.
So a shut down sequence is needed to only write to the EEPROM at shut down. This is not hard for scheduled shut downs but can be a "trick" for power failures.

For now you can have the value written to The EEPROM each time the variable is incremented.

Are you still using a 16F684 ?

LEDave
- 27th April 2010, 16:13
How about remembering something?

I'm a carer, I know a thing or two about remembering.....:)


Are you still using a 16F684 ?

Yes still with the 16F684, do I need a more suitable chip?

Just an aside here, I was looking at in the RS catalogue the other day, they have a PICKit2 for a good price. Is this the next one up for me? Or should I stick with the PICkit1 for now?

http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=0149613

mackrackit
- 27th April 2010, 16:24
The 16F684 is fine for now. It all depends on what you need to do. More I/Os, memory, built in hardware? But for learning the small ones are good.

I am a big fan of the PicKit2 so if you can get one at a good price do so. But for now the PicKit1 is fine for the parts you are using. It is just very limited parts wise.

What do you have in mind to do with all of this? Home automation/monitoring?

There is so much that can be done with the "small" parts and they can be made to share information they may be all you need.

LEDave
- 27th April 2010, 16:45
What do you have in mind to do with all of this? Home automation/monitoring?

You know I really don't have a direct answer to that one. I've got a couple of small projects in the offing (I'll tell you about them later) and some ideas.The thing is, it's almost unlimited in what you can do! For me right now, it's about building a sound knowledge base, plus it's really absorbing, fascinating, I love it.

Dave

LEDave
- 29th April 2010, 00:12
Hi mackrackit,

I've been busy working on the last assignment....:)

Quick question. Would the code (below) output the value of B_P onto my LCD? B_P is a VAR WORD. I've used DEC1 as I only want to test the output with a couple of button presses (if that makes sense).


LCDOUT $FE,1
LCDOUT $FE,DEC1 B_P

Dave

mackrackit
- 29th April 2010, 01:35
Well... what did you get on your display?


B_P = 12345
LCDOUT $FE,$C0,DEC1 B_P 'Displays 5

LCDOUT $FE,$C0,DEC2 B_P 'Displays 45

LCDOUT $FE,$C0,DEC3 B_P 'Displays 345

LCDOUT $FE,$C0,DEC4 B_P 'Displays 2345

LCDOUT $FE,$C0,DEC5 B_P 'Displays 12345

LCDOUT $FE,$C0,DEC B_P 'Displays 12345

LEDave
- 29th April 2010, 21:24
Hi mackrackit,

Really sorry for the late reply, has been one of those days today.

I've got a couple of small problems with LCD / Counting at the moment, nothing I shouldn't be able to fix by now so please bear with me. If I can't get it going soon I'll have to ask.

Dave

mackrackit
- 29th April 2010, 22:44
Really sorry for the late reply, has been one of those days today.
Days???
I have been having one of those weeks :p

LEDave
- 30th April 2010, 00:07
Hi mackrackit,


I have been having one of those weeks:p

Lol..... Nice to know I'm not alone, you do have my sympathy though.

Here's what I thought was a silly question, now I'm not so sure it is:

When you declare a VAR WORD, I thought that the value would automatically be set at zero, now I'm not so sure it is. Do you have to have to re-set it to zero before you start a count program or is it zero already?

I know it's Friday tomorrow but I hope your week gets better.

Dave

mackrackit
- 30th April 2010, 00:14
Sometimes it will be zero at power up but you never know.

You can use CLEAR, in the manual

or

VAR_IN_QUESTION = 0

Not a stupid question at all :)

LEDave
- 30th April 2010, 00:26
Not a stupid question at all :)

Cheers mackrackit, I'm feeling better already I hope you are too!

So probably good practice to set VAR_IN_QUESTION = 0 just in case.

Hopefully I'll have moved the program on tomorrow, fingers x'd.

Right, time for me bed.

See you tomorrow.

Dave

mackrackit
- 30th April 2010, 10:59
Hint
COUNT is for pulses in a time period.

Maybe
if switch goes high
then
var = var + 1

LEDave
- 30th April 2010, 17:11
Hi mackrackit,

Question: How long does it take LEDave to wire a push_button_switch to a PIC16F684?

Answer: About 48hrs:eek:

I think the program below should work ok:


Total var word
clear

MAIN:
if PORTA.5 = 0 then count_up:
IF PORTA.5 = 1 THEN MAIN:

Count_up:
let Total = Total + 1
pauseus 25
LCDOUT $FE,1
LCDOUT $FE,$C0,DEC Total
PAUSE 500
GOTO MAIN:

LEDave current status: Eyes going, mind boarderline!

Dvae

mackrackit
- 30th April 2010, 17:24
I think the program below should work ok:


Total var word
clear

MAIN:
if PORTA.5 = 0 then count_up:
IF PORTA.5 = 1 THEN MAIN:

Count_up:
let Total = Total + 1
pauseus 25
LCDOUT $FE,1
LCDOUT $FE,$C0,DEC Total
PAUSE 500
GOTO MAIN:
It looks good.


LEDave current status: Eyes going, mind boarderline!

Dvae Hey, that means you have passed the initiation and are a full codder now. :p

LEDave
- 30th April 2010, 17:29
So the next thing it to WRITE 'Total' to EEPROM address, then READ that value and put it back into 'Total'.

The theory is that when the PIC power supply is turned off then restarted last 'Total' reappears on the LCD.

Dave

mackrackit
- 30th April 2010, 17:35
Yup, that is the mission :)

LEDave
- 30th April 2010, 18:03
From the manual:


WRITE Address,Value

So looking at the 16F684.PDF it says:


The PIC16F684 has 256 bytes of data EEPROM
with an address range from 0h to FFh.

So would:
WRITE 0h,Total work? Not quite as simple as that he says! For one thing these are EEPROM BYTES and 'Total' is a WORD two BYTES for a starter.

Dvae

mackrackit
- 30th April 2010, 18:08
You do not need to use HEX numbers for the address, PBP takes care of that.

http://www.melabs.com/resources/samples.htm
Might find the above .... interesting

LEDave
- 30th April 2010, 22:32
Mmm. Well I kind of think I know what I have to do, it's break the VAR WORD Total up into two BYTES, allocate them each a memory space B1 & B1+1 (from the prog below) WRITE the BYTES to the memory locations then READ them back.


INCLUDE "modedefs.bas" ' Include serial modes

SO VAR PORTC.6 ' Define serial output pin

B1 VAR BYTE ' Address variable
W2 VAR WORD ' Data variable


mainloop:

For B1 = 0 To 12 step 2 ' Step 2 because each word requires 2 bytes of memory
W2 = B1 + 1000 ' Add 1000 to address
Write B1, W2.HIGHBYTE ' Write high byte of word
Write B1+1, W2.LOWBYTE ' Write low byte of word to next address
Next B1

For B1 = 0 To 12 step 2 ' Step 2 to get word size data
Read B1, W2.HIGHBYTE ' Read high byte
Read B1+1, W2.LOWBYTE ' Read low byte
SerOut SO,T2400,[#W2," ",10,13] ' Display the word data
Next B1

SerOut SO,T2400,[10,13,10,13] ' Skip 2 Lines

GoTo mainloop ' Forever

My reading of the program above is that B1 = 's ( 0,2,4,6,8,10,12) + 1000 this is then written and read from memory location B1 & B1+1 into WORD W2 am I close?

Dave

mackrackit
- 30th April 2010, 22:44
My reading of the program above is that B1 = 's ( 0,2,4,6,8,10,12) + 1000 this is then written and read from memory location B1 & B1+1 into WORD W2 am I close?

Sounds like you understand it. Have you tried it yet?

LEDave
- 30th April 2010, 22:49
Sounds like you understand it. Have you tried it yet?

I'm on it.......

LEDave
- 30th April 2010, 23:08
I modified it to run on my LCD and it counts from 1000 to 1012 by adding two, then does it all over again.

So the first loop is WRITING the count to memory and the second is READING and displaying from memory to the LCD. B1 being the high BITS of the BYTE that make up W2 and B1+1 the low bits of W2, is that right?

So to complete our 'mission' should I try and do the same and use a loop or assign BYTES to a WORD (if that makes sense).

Dave

mackrackit
- 30th April 2010, 23:23
I modified it to run on my LCD and it counts from 1000 to 1012 by adding two, then does it all over again.

So the first loop is WRITING the count to memory and the second is READING and displaying from memory to the LCD. B1 being the high BITS of the BYTE that make up W2 and B1+1 the low bits of W2, is that right?
Yup!


So to complete our 'mission' should I try and do the same and use a loop or assign BYTES to a WORD (if that makes sense).

Dave
????

You have the WORD size var holding the value of how many times the switch was pressed. Use the high byte low byte thing from above for writing every time the switch is pressed. Only need to read the EEPROM when the chip starts.

Something like that:)

LEDave
- 30th April 2010, 23:49
Something like that:)

I'll give it a go, not a 100% sure on this one but I'll give it go.

This is brilliant stuff though, cheers mackrackit.

Dave

mackrackit
- 1st May 2010, 00:01
Mission clarification

Power UP
Read EEPROM
Transfer value from EPROM to VAR

Press Button
VAR adds one to it's self
Display VAR on LCD
Write VAR to EEPROM
Wait for another Button press

This message will self destruct in.....

LEDave
- 1st May 2010, 09:26
:):):)

I'm on it boss 'NCIS'.....!

Dave

LEDave
- 3rd May 2010, 00:28
Hi mackrackit,

I've not been able able to look at the project this weekend due to a family issue.

Will be back 'on mission' tomorrow all being well.

Dave

mackrackit
- 3rd May 2010, 01:55
Yup, family comes first. In the end that is all we got.

Hope things turn out well.

LEDave
- 3rd May 2010, 23:39
Yup, family comes first. In the end that is all we got.

Never a truer word....


Hope things turn out well.

Thank you and they have I'm very relieved to say.

Back on the case tomorrow after a good nights sleep.

Dave

LEDave
- 4th May 2010, 17:37
Hi mackrackit,

Things pretty much back to normal here (panic over):)

So here's the first part of the brief, I think it covers these components:


Power UP: Read EEPROM: Transfer value from EPROM to VAR: Press Button:
VAR adds one to it's self: Display VAR on LCD

I didn't want to try and do any more just in case I'm wildly off track on this, what do you think? I've left out all the DEFINES for clarity.


Total var word ' Data variable
B1 VAR BYTE 'Stored DATA address
clear 'Re_set volatile memory to zero (Not EEPROM?)

MAIN:
gosub Power_up 'On Power_up GOTO READ EEPROM subroutine
Start:
if PORTA.5 = 0 then count_up: 'If button pressed start counting
IF PORTA.5 = 1 THEN Start: 'If button not pressed loop until it is

Count_up: 'Button has been pressed
let Total = Total + 1 'Add one to value of Total taken from EEPROM
LCDOUT $FE,1 'Clear LCD
LCDOUT $FE,$C0,DEC Total 'Display Total on LCD
PAUSE 500
GOTO Start:

Power_up: 'Power_up subroutine
Read B1, Total.HIGHBYTE ' Read high byte
Read B1+1, Total.LOWBYTe ' Read low byte
LET Total = Total 'Set Total to value set in EEPROM Memory
return

Dave

mackrackit
- 4th May 2010, 17:55
Glad to hear things are back to normal.

A quick look and it looks OK, might want to add a WRITE to EEPROM routine though...

LEDave
- 4th May 2010, 18:18
Glad to hear things are back to normal.

Cheers mackrackit, it was a real worry there for a while.....


might want to add a WRITE to EEPROM routine though...

I'm be on it tonight.

Dave

LEDave
- 4th May 2010, 20:03
Hi mackrackit,

I've added the WRITE to EEPROM routine. Also @power_up the LCD was blank, so I
added an LCDOUT statement to the Power_up Subroutine which now displays the last stored
EEPROM value.

The whole thing works a treat:):) I can see the merits of being able to write data to a non volatile memory, really,really useful. Thanks for stearing me through this one (as ever) very clever.



Total var word ' Data variable
B1 VAR BYTE 'Stored DATA address
clear 'Re_set volatile memory to zero (Not EEPROM?)

MAIN:
gosub Power_up 'On Power_up GOTO READ EEPROM subroutine

Start:
if PORTA.5 = 0 then count_up: 'If button pressed start counting
IF PORTA.5 = 1 THEN Start: 'If button not pressed loop until it is

Count_up: 'Button has been pressed
let Total = Total + 1 'Add one to value of Total taken from EEPROM

LCDOUT $FE,1 'Clear LCD
pause 150
LCDOUT $FE,$C0,DEC Total 'Display Total on LCD
Write B1, Total.HIGHBYTE ' Write high byte of Total word to EEPROM
Write B1+1, Total.LOWBYTE ' Write low byte of Total word to next address
goto start:

Power_up: 'Power_up subroutine
Read B1, Total.HIGHBYTE ' Read high byte
Read B1+1, Total.LOWBYTe ' Read low byte
LET Total = Total 'Set Total to value set in EEPROM Memory
LCDOUT $FE,1 'Clear LCD
pause 150 'Give LCD a chance to Power_up
LCDOUT $FE,$C0,DEC Total 'At Power_up display Total on LCD from EEPROM
'Memory which has been stored since Power_down
return


Just going to pop around my bench to turn the power back on........Yep still working :)

Dave

mackrackit
- 4th May 2010, 20:15
COOL!!!!:D

Do you want another mission? :p

LEDave
- 4th May 2010, 21:29
Do you want another mission?

You bet, I wanted you to sign me off on the last Mission first though:D

It's one thing me thinking I've done something right, it's another being told I have.

Dave

mackrackit
- 4th May 2010, 22:07
So far you have been letting PBP take care of the EEPROM address "B1".
Now we want to control where in the EEPROM data is written to as we will be storing and retrieving multiple pieces of data.

Using the same basic scenario as before, part counting on a conveyor.
This time the machine and personnel have been upgraded to run 24/7. The only time the machine will be shut down is for maintenance, scheduled or un-scheduled.

Management still wants to know the total parts ran, and the maintenance department wants to know how many parts are being ran between shut downs, how many shut downs there were and because they are lazy they also want the machine to average the amount of parts ran between each down.

Who says computers and automation cuts jobs? We went from running one shift to three and added coder to the mix along with all of the supply/demand personnel to handle the increased production.

LEDave
- 4th May 2010, 23:04
Ok.....Mmm...,


Now we want to control where in the EEPROM data is written to as we will be storing and retrieving multiple pieces of data.

Well for this I'm thinking (although I could be wrong here):


WRITE 5,B0 ' Send value in B0 to EEPROM location 5

So we need:

1/ Total parts run

2/ Total parts run before M/C stops for maintenance

3/ How many times M/C shuts down (scheduled + un_scheduled)

4/ The average amount of parts run between each shut down (scheduled + un_scheduled)

I think I've read that right?

Dave

mackrackit
- 4th May 2010, 23:32
WRITE 5,B0 ' Send value in B0 to EEPROM location 5
Yup


1/ Total parts run

2/ Total parts run before M/C stops for maintenance For each run, need multiple address here too.

3/ How many times M/C shuts down (scheduled + un_scheduled)

4/ The average amount of parts run between each shut down (scheduled + un_scheduled)
Remember two address locations for WORD size variables.
Hopefully the machine will run long enough to need a WORD VARs for parts run between shut downs, and if all goes well the machine will not shut down often so a BYTE size VAR should work for "times shut down".

LEDave
- 4th May 2010, 23:46
I'm on it, tricky in parts but I'm on it:)

How many EEPROM locations are there on a PIC16F684?

As in:


EEPROM location 5

Dave

mackrackit
- 5th May 2010, 00:04
I think the 684 only has 256, if I remember correctly.

LEDave
- 5th May 2010, 00:36
Is that sequential 0-255?

Srub that, it's got to be I'm thinking.

See you tomorrow.

Dave

LEDave
- 5th May 2010, 22:56
Hi mackrackit,

I'm busy working on the latest 'mission'. I'll stick at it and only ask a question when I'm stuck and have given it a good go to figure it out myself.

I do have one quick question though:

Can you add or subtract EEPROM memory location values (numbers written to an EEPROM address)? Or do you just give the stored WORD's a name and then subtract the two, something like: Parts_Run = Total - First_Parts_run (if this make sense).

Dave

mackrackit
- 6th May 2010, 03:17
While the value is in the EEPROM you can not go anything with it. You have to read the value into a variable, do something with it and write it back into the EEPROM.

I think that is what you are asking...

LEDave
- 6th May 2010, 08:35
I think that is what you are asking...

Spot on.

Dave

LEDave
- 6th May 2010, 16:52
I can almost hear mackrackit tapping his fingers on the table............!;)

Working really hard on this, I know what I want to do, I just need a breakthrough. At the moment I'm going around in circles.

I'll see what I can come up with tonight.


Tap, tap, tap...Stop it mackrackit...lol.

mackrackit
- 6th May 2010, 17:58
Going around in circles?
You mean stuck in a loop :D

tap tap tap
that is funny :)

LEDave
- 6th May 2010, 22:02
You mean stuck in a loop :)

Yep,exactly that:eek:

If I can't crack it by tomorrow night I'm going to have to ask for a pointer. I was going to ask for one tonight but I think I'm in the right ball park for a small break through (he typed deludedly but hopefully).

Dave

LEDave
- 7th May 2010, 16:56
Mmmm,
You mean stuck in a loop

Cryptic I know but are you 'hinting' that the way to do part two of the mission, namely:


Total parts run before M/C stops for maintenance For each run

Is to have the Total count (part one of mission) actually run inside a WORD size loop and Total parts run is actually the loop count itself? So that whenever the loop stops (ie, MC stops) that value is then written to EEPROM as Total parts run?

The thinking would then be that Total count just carries on and parts run ie the loop count resets to zero and then starts again on power up.

Dave

mackrackit
- 7th May 2010, 18:05
The thinking would then be that Total count just carries on and parts run ie the loop count resets to zero and then starts again on power up.
And writes to a different EEPROM location each time. So if you have five start ups you will have five EEPROM locations (10 actually, 2 per WORD), plus the pair of locations for the TOTAL.

LEDave
- 7th May 2010, 18:20
And writes to a different EEPROM location each time.

More to think about there then.All part of the learning process.

Learning how to program these PIC's is like learning a foreign language, doing a crossword puzzle and a Rubick's cube (all at the same time)...:eek:

It'll come with time and practice though (I hope...!)

Dave

mackrackit
- 7th May 2010, 19:47
Sometimes understanding the process is the difficult part. When I am asked to help modify a machine from manual to auto I will set up a video recorder so I can study the complete sequence the machine is expected to go through.

In my last post I forgot a variable. You will need a variable to remember how many times the machine has been started. Let's call this M_S.

The first time the machine starts all EEPROM locations will have the value of zero.
So the first thing will be to increment M_S to 1 and save that.
Now the machine will go into normal operation.
The TOTAL is incrementing. Saving to EEPROM.
The Parts_Run is incrementing. Saving to EEPROM, this location could have the name of PS_1.

The machine is shut down and re-started.
The TOTAL EEPROM location(s) is read and the value is placed into var TOTAL.
M_S is read and if it is 1 then two things need to happen. M_S will now be incremented and saved back to EEPROM. Now the Parts_Run value will need to write to another EEPROM location, this location could be named PS_2.

The number of parts ran the first time will be unchanged. You may want to display this on the LCD.

The same thing will happen each time the machine re-starts withe the Parts Run value saving to a different EEPROM location.

Lets say you set this up for 5 re-starts.


TOTAL VAR WORD 'STORED IN EEPROM LOCATIONS 0 AND 1
PS_1 VAR WORD 'STORED IN EEPRON LOCATIONS 2 AND 3
PS_2 VAR WORD 'STORED IN EEPRON LOCATIONS 4 AND 5
PS_3 VAR WORD 'STORED IN EEPRON LOCATIONS 6 AND 7
PS_4 VAR WORD 'STORED IN EEPRON LOCATIONS 8 AND 9
PS_5 VAR WORD 'STORED IN EEPRON LOCATIONS 10 AND 11
M_S VAR BYTE 'STORED IN EEPRON LOCATIONS 12 AND 13

LEDave
- 7th May 2010, 20:38
Cheers mackrackit,

I can see that it would be a good idea to actually draw up what it is I'm trying to achieve rather than just 'coding' as an idea arrives. These programs can soon grow and become very complicated.

Will be a good 'mission' to achieve this one, I've learned and am still learning from it.

Dave

LEDave
- 8th May 2010, 19:01
Hi mackrackit,

From the brief:


M_S VAR BYTE 'STORED IN EEPRON LOCATIONS 12 AND 13

Does M_S need to be set as a BYTE or a WORD? If it's a BYTE is this ok?


WRITE 12, M_S

Dave

mackrackit
- 8th May 2010, 19:15
Good catch. It only needs to be a BYTE with one EEPROM location in this app.

LEDave
- 8th May 2010, 19:59
Good catch.

More a stumble than a catch (program wouldn't compile):)

Dave

LEDave
- 8th May 2010, 22:58
Hi mackrackit,

Slow but steady progress tonight. I wouldn't go so far as to say the end is in sight but things are moving along.

Now here's a question. Since I joined this FORUM in February I think it was. I've gone from not being able to blink an LED to having a working LCD in under 12 weeks, not to mention the Serial Communicator and other stuff we've done.

So here's the question: Have you ever considered writing a book for 'Newbies' like me? I'll be perfrectly honest here, determined as I am, if I hadn't found this FORUM, well I would really has struggled to move on let's put it that way.

Just a thought.

Dave

mackrackit
- 9th May 2010, 06:30
BOOK :eek:
Nope, I have though about getting an "education" so I could teach at the local college though. That would be fun.

The problem I have with books are the authors. The is a popular author out there on this subject that is even a member of this forum. Many newbies come to this forum after reading his book(s) and they still do not know much more than you did when you came here. Does the book author help out on the forum? Nope. So it seems there are books out there with out support. What good is that other than the author making money.

So I figure if someone wants to learn, skip the book and go straight to the people that really want to help others learn. For PBP that would be this forum.

Keep hanging out here on the forum, read every post and take lots of notes, when you see someone with a problem and you have an answer post it.

Then someday someone will say to you, have you ever considered writing a ......

LEDave
- 9th May 2010, 18:00
:)

I hear what you're saying mackrackit.


Keep hanging out here on the forum, read every post and take lots of notes, when you see someone with a problem and you have an answer post it.

That would be nice, to be able to give something back to the FORUM...One day!

Dave

LEDave
- 9th May 2010, 19:56
UPDATE:

I'm getting steadily closer.....!

One piece of the program isn't doing what I want it to.....Grrr.

I may have to ask for a pointer.

Dave

mackrackit
- 10th May 2010, 08:21
A pointer??
http://en.wikipedia.org/wiki/Pointer_%28computing%29
:D :D

LEDave
- 10th May 2010, 17:02
Well I gave a good go and in the end my lack of knowledge failed me.:(

Here's what the program does:

1/ It displays the 'Total' on line one.
2/ It displays the number of Machine Starts on line two.

Here's where things go wrong though. On line three it displays the Parts run count 1-5 but the number of parts run between stops always equals 'Total' and not 'Total - parts run' ie the difference.

I've spent hours trying to crack it but I'm missing something.

I'll post the whole program below, I'm sure there's lots of unnecessary and duplicated code (not to mention mistakes) within the program but hey I'm still a 'Newbie'.

Dave

LEDave
- 10th May 2010, 17:03
ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00100000 'Set PORTA.5 as INPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 150

DEFINE OSC 4

TOTAL VAR WORD 'STORED IN EEPROM LOCATIONS 0 AND 1
PS_1 VAR WORD 'STORED IN EEPRON LOCATIONS 2 AND 3
PS_2 VAR WORD 'STORED IN EEPRON LOCATIONS 4 AND 5
PS_3 VAR WORD 'STORED IN EEPRON LOCATIONS 6 AND 7
PS_4 VAR WORD 'STORED IN EEPRON LOCATIONS 8 AND 9
PS_5 VAR WORD 'STORED IN EEPRON LOCATIONS 10 AND 11
M_S VAR BYTE 'STORED IN EEPRON LOCATIONS 12

clear 'Re_set volatile memory to zero (Not EEPROM?)

MAIN:

gosub MC_S 'Set & increment M/C Starts Total subroutine
gosub Power_up 'On Power_up GOTO READ EEPROM subroutine
gosub Parts_Run 'Number of parts made


Start:
if PORTA.5 = 0 then count_up: 'If button pressed start counting
IF PORTA.5 = 1 THEN Start: 'If button not pressed loop until it is

Count_up: 'Button has been pressed
let Total = Total + 1 'Add one to value of Total taken from EEPROM
pause 100
LCDOUT $FE,2,"Total=",DEC TOTAL 'Display Total on LCD
Write 0, Total.HIGHBYTE ' Write high byte of Total word to EEPROM
Write 1, Total.LOWBYTE ' Write low byte of Total word to next address
GOTO sTART:

MC_S: 'MC Starts subroutine
READ 12, M_s 'Read current number of M/C Starts
LET M_S = M_S + 1 'Increment value by one
WRITE 12, M_S 'Save new value
READ 12, M_s 'Read latest value
pause 150 'Give LCD a chance to Power_up
LET M_S = M_S 'Set value to display
LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
RETURN


Power_up: 'Power_up subroutine
Read 0, Total.HIGHBYTE ' Read high byte
Read 1, Total.LOWBYTe ' Read low byte
LET Total = Total 'Set Total to value set in EEPROM Memory
pause 150 'Give LCD a chance to Power_up
LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
'Memory which has been stored since Power_down
return

Parts_Run:
SELECT CASE M_S
CASE 1
if M_s = 1 then PARTS1:
CASE 2
IF M_S = 2 THEN PARTS2:
CASE 3
IF M_S = 3 THEN PARTS3:
CASE 4
IF M_S = 4 THEN PARTS4:
CASE 5
IF M_S = 5 THEN PARTS5:
END SELECT
RETURN

PARTS1:
let PS_1 = Total
WRITE 2,PS_1.HIGHBYTE
WRITE 3,PS_1.LOWBYTE
READ 2,PS_1.HIGHBYTE
READ 3,PS_1.LOWBYTE
LET PS_1 = PS_1
PAUSE 150
LCDOUT $FE, $94,"Parts1=",DEC PS_1
return


PARTS2:
LET PS_2 = Total - PS_1
WRITE 4,PS_2.HIGHBYTE
WRITE 5,PS_2.LOWBYTE
READ 4,PS_2.HIGHBYTE
READ 5,PS_2.LOWBYTE
LET PS_2 = PS_2
PAUSE 150
LCDOUT $FE, $94,"Parts2=",DEC PS_2
return


PARTS3:
LET PS_3 = TOTAL - PS_2
WRITE 6,PS_3.HIGHBYTE
WRITE 7,PS_3.LOWBYTE
READ 6,PS_3.HIGHBYTE
READ 7,PS_3.LOWBYTE
LET PS_3 = PS_3
PAUSE 150
LCDOUT $FE, $94,"Parts3=",DEC PS_3
return


PARTS4:
LET PS_4 = TOTAL - PS_3
WRITE 8,PS_4.HIGHBYTE
WRITE 9,PS_4.LOWBYTE
READ 8,PS_4.HIGHBYTE
READ 9,PS_4.LOWBYTE
LET PS_4 = PS_4
PAUSE 150
LCDOUT $FE, $94,"Parts4=",DEC PS_4
return


PARTS5:
LET PS_5 = TOTAL - PS_4
WRITE 10,PS_5.HIGHBYTE
WRITE 11,PS_5.LOWBYTE
READ 10,PS_5.HIGHBYTE
READ 11,PS_5.LOWBYTE
LET PS_5 = PS_5
PAUSE 150
LCDOUT $FE, $94,"Parts5=",DEC PS_5
return

mackrackit
- 10th May 2010, 19:10
I am on a very small display right now so I might be missing something...

It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.

LEDave
- 10th May 2010, 19:58
Cheers mackrackit,


It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.

I'll have a think about that one and make some changes.

Dave

LEDave
- 10th May 2010, 22:07
Ok, I've got an idea to work on now (I was lost before). So each PS_1 - 2 - 3 etc, are all individual counting loops.So each time 'Total does one count it then enters PS_n so yo have one Total counter and five PS_n counters.

I'm back on the scent now......:)

Cheers mackrackit.

Dave

mackrackit
- 10th May 2010, 22:15
In think you got it now.
I made this up but you may not need it, sometimes even a "bad" flowchart helps.
4382

LEDave
- 11th May 2010, 00:06
Brilliant flowchart mackrackit:cool:

Yes over the last hurdle now (I think). I've got PS_1-5 counting their own totals. Small problem in that the counts started from one all the time, then I realised that the button condition could set the count which your flow chart confirmed:)

All being well the 'Mission' will be completed tomorrow.

Watch this space...

Dave

LEDave
- 11th May 2010, 15:45
One last question (I think).

The very first time the M/C is started we want 'Total' to equal zero (after all nothing's been made yet) So how do I initialize EEPROM 'Total' to zero the first time the M/C runs?. The second time it starts it reads the stored value of 'Total' and adds to that.

The reason I'm asking this is because every time I compile and run the program, there seems to be a value already stored on EEPROM 'Total'.

Dave

mackrackit
- 11th May 2010, 16:21
Probably the best way for testing would be to write a program that writes zero to all of the EEPROM locations that you are using then re-code the chip with your main program.

If this was for real life then a hidden reset switch or jumper could have a routine to write zeros run. Then when the jumper is removed the code jumps over the zero routine and runs the main program.

LEDave
- 11th May 2010, 16:39
Cheers mackrackit

So allowing for the fact that Total may contain 'random' data at start I think I've finished the 'Mission'....Hoorah!

I've added the average parts run over the five runs on line four of the LCD. Here's the program. What do you think?:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00100000 'Set PORTA.5 as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00000000 'Set PORTC as OUTPUT.
PORTC = %00000000 'Set PORTC pins all low.

DEFINE LCD_DREG PORTC 'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4 'PORTC.4 CONNECT TO LCD PIN4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5 'PORTC.5 CONNECT TO LCD PIN6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 150

DEFINE OSC 4

TOTAL VAR WORD 'STORED IN EEPROM LOCATIONS 0 AND 1
PS_1 VAR WORD 'STORED IN EEPRON LOCATIONS 2 AND 3
PS_2 VAR WORD 'STORED IN EEPRON LOCATIONS 4 AND 5
PS_3 VAR WORD 'STORED IN EEPRON LOCATIONS 6 AND 7
PS_4 VAR WORD 'STORED IN EEPRON LOCATIONS 8 AND 9
PS_5 VAR WORD 'STORED IN EEPRON LOCATIONS 10 AND 11
M_S VAR BYTE 'STORED IN EEPRON LOCATIONS 12
AV_Parts_Run var word 'STORED IN EEPRON LOCATIONS 13 AND 14

clear 'Re_set volatile memory to zero (Not EEPROM?)

MAIN:
gosub MC_S 'Set & increment M/C Starts Total subroutine
gosub Power_up 'On Power_up GOTO READ EEPROM subroutine


Start:
if PORTA.5 = 0 then count_up: 'Button pressed start counting
IF PORTA.5 = 1 THEN Start: 'If button not pressed loop until it is

Count_up: 'Button has been pressed
let Total = Total + 1 'Add one to value of Total taken from EEPROM
pause 100
LCDOUT $FE,2,"Total=",DEC TOTAL 'Display Total on LCD
Write 0, Total.HIGHBYTE ' Write high byte of Total word to EEPROM
Write 1, Total.LOWBYTE ' Write low byte of Total word to next address
gosub Parts_Run 'Number of parts made
GOTO START:

MC_S: 'MC Starts subroutine
READ 12, M_s 'Read current number of M/C Starts
LET M_S = M_S + 1 'Increment value by one
WRITE 12, M_S 'Save new value
READ 12, M_s 'Read latest value
pause 150 'Give LCD a chance to Power_up
LET M_S = M_S 'Set value to display
LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
RETURN

Power_up: 'Power_up subroutine
Read 0, Total.HIGHBYTE ' Read high byte
Read 1, Total.LOWBYTe ' Read low byte
LET Total = Total 'Set Total to value set in EEPROM Memory
pause 150 'Give LCD a chance to Power_up
LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
'Memory which has been stored since Power_down
return

Parts_Run:
SELECT CASE M_S
CASE 1
if M_s = 1 then PARTS1:
CASE 2
IF M_S = 2 THEN PARTS2:
CASE 3
IF M_S = 3 THEN PARTS3:
CASE 4
IF M_S = 4 THEN PARTS4:
CASE 5
IF M_S = 5 THEN PARTS5:
END SELECT
RETURN

PARTS1:
let PS_1 = PS_1 + 1
WRITE 2,PS_1.HIGHBYTE
WRITE 3,PS_1.LOWBYTE
READ 2,PS_1.HIGHBYTE
READ 3,PS_1.LOWBYTE
LET PS_1 = PS_1
PAUSE 150
LCDOUT $FE, $94,"Parts1=",DEC PS_1
return


PARTS2:
LET PS_2 = PS_2 + 1
WRITE 4,PS_2.HIGHBYTE
WRITE 5,PS_2.LOWBYTE
READ 4,PS_2.HIGHBYTE
READ 5,PS_2.LOWBYTE
LET PS_2 = PS_2
PAUSE 150
LCDOUT $FE, $94,"Parts2=",DEC PS_2
return


PARTS3:
LET PS_3 = PS_3 + 1
WRITE 6,PS_3.HIGHBYTE
WRITE 7,PS_3.LOWBYTE
READ 6,PS_3.HIGHBYTE
READ 7,PS_3.LOWBYTE
LET PS_3 = PS_3
PAUSE 150
LCDOUT $FE, $94,"Parts3=",DEC PS_3
return


PARTS4:
LET PS_4 = PS_4 + 1
WRITE 8,PS_4.HIGHBYTE
WRITE 9,PS_4.LOWBYTE
READ 8,PS_4.HIGHBYTE
READ 9,PS_4.LOWBYTE
LET PS_4 = PS_4
PAUSE 150
LCDOUT $FE, $94,"Parts4=",DEC PS_4
return


PARTS5:
LET PS_5 = PS_5 + 1
WRITE 10,PS_5.HIGHBYTE
WRITE 11,PS_5.LOWBYTE
READ 10,PS_5.HIGHBYTE
READ 11,PS_5.LOWBYTE
LET PS_5 = PS_5
PAUSE 150
LCDOUT $FE, $94,"Parts5=",DEC PS_5

READ 2,PS_1.HIGHBYTE
READ 3,PS_1.LOWBYTE
LET PS_1 = PS_1
READ 4,PS_2.HIGHBYTE
READ 5,PS_2.LOWBYTE
LET PS_2 = PS_2
READ 6,PS_3.HIGHBYTE
READ 7,PS_3.LOWBYTE
LET PS_3 = PS_3
READ 8,PS_4.HIGHBYTE
READ 9,PS_4.LOWBYTE
LET PS_4 = PS_4
READ 10,PS_5.HIGHBYTE
READ 11,PS_5.LOWBYTE
LET PS_5 = PS_5

let AV_Parts_Run = (PS_1 + PS_2 + PS_3 + PS_4 + PS_5)/5
write 13,AV_parts_Run.HIGHBYTE
WRITE 14,AV_Parts_Run.LOWBYTE
READ 13,AV_parts_Run.HIGHBYTE
READ 14,AV_Parts_Run.LOWBYTE
let AV_Parts_Run = AV_Parts_Run
PAUSE 150
LCDOUT $FE, $D4,"AV_Parts_Run =",DEC AV_Parts_Run
end

mackrackit
- 11th May 2010, 17:00
I am on the road again with a small display but what I can see looks good!:)

I take you have ran it a few times and it is working as expected?

LEDave
- 11th May 2010, 18:05
I take you have ran it a few times and it is working as expected?

:eek::eek::eek: I've got a bug (it maybe a small infestation!)...(I could have swore it worked earlier!)

I spoke too soon, 'Mission' incomplete. I'll try and debug it later tonight.

Dave

mackrackit
- 12th May 2010, 05:31
I added a couple things, messes up your averaging part (never gets there now) but maybe this will help.
Other than that it is looking good!!!!


MC_S: 'MC Starts subroutine
READ 12, M_s 'Read current number of M/C Starts
LET M_S = M_S + 1 'Increment value by one
'#######
IF M_S > 5 THEN
M_S = 0
ENDIF
'#######
WRITE 12, M_S 'Save new value
READ 12, M_s 'Read latest value
pause 150 'Give LCD a chance to Power_up
LET M_S = M_S 'Set value to display
LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
RETURN

Power_up: 'Power_up subroutine
Read 0, Total.HIGHBYTE ' Read high byte
Read 1, Total.LOWBYTe ' Read low byte
'#######
IF TOTAL > 5000 THEN
TOTAL = 0
ENDIF
'#######
LET Total = Total 'Set Total to value set in EEPROM Memory
pause 150 'Give LCD a chance to Power_up
LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
'Memory which has been stored since Power_down
return

LEDave
- 12th May 2010, 16:33
Hi mackrackit

Thanks for the 'addins' I've run the program and apart from 'Total' (when the program starts for the first time after compiling not equalling zero) I reckon it works, even the Av_Parts_Run works if you subtract that spurious 'Total' figure, so well pleased.

What do you reckon?

Dave

mackrackit
- 12th May 2010, 16:56
Set things up so when a pin is held HIGH at start-up the EEPROM is re-set to zeros. Then you should have a complete counting/storage system that can be re-set.

Now we have to think of something else for you to do :D

LEDave
- 12th May 2010, 18:44
Set things up so when a pin is held HIGH at start-up the EEPROM is re-set to zeros. Then you should have a complete counting/storage system that can be re-set.

Gotcha......:)


Now we have to think of something else for you to do"

How about this for a quick diversion: How are we on using a PIC to drive a servo motor?

We've been getting a visitor to our garden late at night (we think it's a Badger) and would like to film it. I've got a FUTABA FP-5148 servo that I'd like to link up to a cable release to press the record button on a video camera after receiving an input from a PIR to the PIC.

The sequence is this:

1/ PIR 'beam' get broken by 'Creature'.
2/ PIC activates servo to move cable release out and turn camera on.
3/ PIC waits 10 secs while camera boots up.
4/ PIC activates servo again moves cable release out turns camera record on (same button).

The camera will record on it's own for 10 mins then powers down.

5/ If PIR been is still broken (creature still there) after 9min:30secs servo presses record button again.

6/ PIR beam 'closes' creature has gone, camera powers down.

What do you think mackrackit?

Dave

mackrackit
- 12th May 2010, 19:12
Sounds like fun...
But what do you do when you find out it is a badger... or not :eek:

Do you have the data sheet for the servo? PIR?

LEDave
- 12th May 2010, 19:46
But what do you do when you find out it is a badger... or not

I hadn't considered the 'or not' option......:eek:


Do you have the data sheet for the servo? PIR?

Well the PIR is just using a set of normally open contacts.The actual PIR is 12V I don't have a data sheet but I'm thinking that if I use 5V on the N/O contacts with a resistor onto the PIC that should be alright (I hope).

The servo itself is a FUTABA FP5148 I don't have a data sheet for this either but I could email Futaba and ask for one (it's and old three wire job) I've looked on their website but all the product numbers have moved on so nothing to go on. It was for a model glider.

It probably an old version of one of these below:

http://www.futaba-rc.com/servos/servos.html

Not much for you to go on mackrackit I know, what do you think though worth a try?

Dave

mackrackit
- 12th May 2010, 19:58
Yip. Worth a try.

Someone here I am sure knows about this servo, voltage and things.
I will guess 5 volts will work.

PIR will be easy...

LEDave
- 12th May 2010, 20:19
Ok the project's underway.

What were you thinking for the next 'Mission' mackrackit?

mackrackit
- 12th May 2010, 20:51
I was thinking something with ADC and LOOKUP tables. But have not really figured out a project yet.

LEDave
- 12th May 2010, 21:12
I was thinking something with ADC and LOOKUP tables. But have not really figured out a project yet.

Sounds very interesting. As ever though as and when mackrackit (you know I appreciate your time and effort putting into me).

I'll try and progress the project for now.

Dave

mackrackit
- 14th May 2010, 05:13
Starting to use servos? here is an interesting thread.
http://www.picbasic.co.uk/forum/showthread.php?t=8000

LEDave
- 14th May 2010, 20:50
Well I wasn't expecting that as a header!:


Automatic Toilet Flusher:D:D:D

Anyroad, some interesting stuff there. A lot of the reading I'm doing on servo's say to use a separate power supply for the motor and common the grounds up. Why would you want to do that? Is it a noise thing?

Dave

LEDave
- 14th May 2010, 21:46
I found this posted by Bruce, kind of answers my last question:


Make sure you're using a separate power supply for your servo, and you have a common ground between them. Running a servo from your controller power supply can cause problems if you aren't using a hefty bench type power supply with a lot of filtering to remove motor noise.

mackrackit
- 15th May 2010, 08:12
Yup, as always Bruce gives good advice.

If the servor is a small one like the ones from the basic stamp folks you can get away with one battery pack and a large capacitor. At least they sell their little robots that way and they do work pretty well.

LEDave
- 17th May 2010, 22:52
PROJECT UPDATE:

PIR was a snip. Works fine off a 12V battery and has a pair of N/C contacts for 5V onto the PIC.

I've managed to mount the servo into a housing and 'rig_up' a bracket to hold the cable release in position for the servo, looks good and should work a treat.

All I need to do now is finish the program. I'm off all this week but Mrs LEDave has had me replacing the garden fence:eek: No sense of priority some people!!!

I'll post my program up asap.

Dave

mackrackit
- 17th May 2010, 23:50
I'm off all this week but Mrs LEDave has had me replacing the garden fence:eek: No sense of priority some people!!!And if the badger is on the outside you may not need this project??? :p

LEDave
- 18th May 2010, 00:13
And if the badger is on the outside you may not need this project:p

Lol....:)

Wooden panels down the sides, wire and post at the bottom, we back onto an open field (Badger friendly fencing!).

That said, they come in from the front, down the side of the building and into the back garden (we think), talk about nerve.

The project will prove once and for all what's going on in the wee hours.

Dave

LEDave
- 18th May 2010, 23:28
Fence update: I should have got a man in..... No, I should have got two men in!

Hopefully tomorrow I'll have a bit of time to set too with the program.

Dave

LEDave
- 21st May 2010, 00:37
Hi mackrackit,

Still struggling for time at the moment. Will get back onto the servo as soon as I can.

Dave

mackrackit
- 21st May 2010, 07:55
Same problem here with time and now I find out that I am getting sent "out of town" for a couple weeks. Not sure how much I will be online for a while.

LEDave
- 21st May 2010, 08:58
Same problem here with time and now I find out that I am getting sent "out of town" for a couple weeks. Not sure how much I will be online for a while.

Put your Boss on, I'll have a word (unless you're being sent to Hawaii or similar?):)

These things happen from time to time. As the BBC say 'Normal service will resume shortly'.

Have a good trip.

Dave

LEDave
- 26th May 2010, 22:56
Hi mackrackit,

I hope your working out of Town is going well and not causing you too many problems?

I've been working on the Servo 'Badger' project these last couple of nights (I've actually been able to make some spare time):)

The project is coming along well now. The PIR puts a 5V input onto PORTC.3 on the PIC which in turn puts a PULSE onto the servo which then moves up and operates the cable release to start the camera. When I finally finish the whole thing I'll put the code up.

Anyway I hope you're keeping well.

Dave

mackrackit
- 26th May 2010, 23:04
Glad the project is going well. Maybe you can post a picture of a badger soon :eek:
Things here went better than expected, now I am back in the shop trying to get caught up on other things... it never ends :)

LEDave
- 27th May 2010, 00:28
Glad the project is going well. Maybe you can post a picture of a badger soon

I should have it rigged to go for the weekend so fingers X'd.

I'm still amazed at the versatility of these PIC's though, is there anything they can't do circuit wise?


Things here went better than expected, now I am back in the shop trying to get caught up on other things... it never ends

Pleased it went well, like you say though....it never does end:eek:

Take it easy.

Dave

LEDave
- 29th May 2010, 21:58
Well I spent hours writing a program to operate a video camera to film the 'Badger' only to find out that the video camera after five minutes powers down and a switch has to be pushed up to re-activate into record mode and then the record button pressed. So a non starter after all that.

I then hooked out my old but simple digital stills camera and re-wrote the program to activate that.The camera stays 'on' when powered up using the mains adaptor:) so no power down problem and I've turned the LCD display off.

All I need to do now is make a simple board up for the PIC (It's on breadboard at the moment) and I should be in business tomorrow night.

Probably not the most accurate program ever written, then again I couldn't turn an LED on this February:( anyway here's the code:


ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.
TRISC = %00001000 'Set PORTC.0 as INPUT.
PORTC = %00000000 'Set PORTC pins all low.


x var byte 'Loop counter Variable
Servo var PORTC.1 'Servo control output_pin
PORTC = 0 'Setup for high_pulsout


MAIN:
PAUSE 50
FOR X = 1 TO 20
PULSOUT Servo,180 'Set the Servo_Arm_Pos (Ready to take a picture)
PAUSE 20
NEXT X

LOOP1:
PAUSE 50
IF PORTC.3 = 0 THEN FIRE: 'PIR Activated (Badger present?)(N/C Contacts opened).
IF PORTC.3 = 1 THEN LOOP1:'PIR Not activated loop until it is.

FIRE: 'Take a picture routine
PAUSE 50
FOR X = 1 TO 20
pulsout servo,130 'Servo_arm moves cable release to take picture
PAUSE 50
NEXT X
pause 1000 'Time for shutter to fire
FOR X = 1 TO 20 'Cable release for camera released / picture taken
PULSOUT Servo,180 'Servo_arm moves back releases cable release
PAUSE 50
NEXT X

PAUSE 10000 'Wait 10 sec's for Camera flash to recycle / recharge
goto LOOP1:


What do you think?

Dave

mackrackit
- 30th May 2010, 03:35
Looks like you are coming right along!

But I am curious about one thing...
What do you plan to do when you find out it is a badger?

LEDave
- 30th May 2010, 08:34
What do you plan to do when you find out it is a badger?

Well just enjoy it and try and take a photo record of it's visits (as long as he / she / they don't start digging the garden up they're more than welcome). We had three Deer that 'visited' a while
back, all was well until they got hungry one night and ate all my wife's shrubs!!! So there are risks attached to 'nature watching'.

Dave

mackrackit
- 30th May 2010, 19:17
Well just enjoy it and try and take a photo record of it's visits (as long as he / she / they don't start digging the garden up they're more than welcome). We had three Deer that 'visited' a while
back, all was well until they got hungry one night and ate all my wife's shrubs!!! So there are risks attached to 'nature watching'.

Dave

COOL :)
Seen a couple bear cams and they were really interesting. Even had cubs in it!

With PIRs and and multiple cams you could track your vistitors from one end of the trail to the other. Interesting project.

LEDave
- 30th May 2010, 23:45
Breaking news. Operation 'Badger' has just gone live......:)

I've had a few teething problems though, the main one being that although the PIR is out in the garden the camera itself is photographing through a double glassed unit and the flash swamps the picture, it looks like snow. The best I could do tonight was move the camera back into the room and alter the camera angle on the trpod to about 45 degrees.If I get a picture I'll zoom in and edit it.

If I get any pictures I'll post them up.


Seen a couple bear cams and they were really interesting. Even had cubs in it!

Probably a very good, not to mention safe way of getting cub footage. I've heard Bears are very protective of their young. A badgers claws are big enough for me:eek:

I might have trouble sleeping tonight, all rather exciting this:)

Dave

LEDave
- 31st May 2010, 16:29
Well here are the results of night one.

I can't really believe it but there he is Mr Badger (or maybe that should be Mrs B not sure) oh and a mystery guest too.

When I woke up this morning there were 48 pictures taken (48!) so the device worked a treat.

Tonight, I'm putting the peanut container on the step right outside the doorway, if he turns up I should get a much clearer photo.

An amazing result for night one though.

Dave

ScaleRobotics
- 31st May 2010, 17:00
Nice results! First try, I like that!

I have not tested at night, but it might help to get your camera right up against the glass, and make a cardboard, or black paper "flash block" that would block some of the light coming from the flash from getting to the glass in front of the lens. As I say, I did not test at night, I just did a test out of a dark window this morning. It seems to be better, but night is the true test. I think if you get rid of some of the flash reflection, you will be better.

But again, congrats on catching a badger the first try!

Walter

mackrackit
- 31st May 2010, 17:15
WOW!!!! THAT IS COOL!!!! :)
One heck of a job!!!

LEDave
- 31st May 2010, 17:36
Hi Walter

Thanks for the tip I'll give that a try.

Dave

LEDave
- 31st May 2010, 17:40
Cheers mackrackit,

I'm really pleased with the results for a first attempt. I must admit I wasn't really expecting to hit the jackpot with the first go:)

Let's see what tonight brings and hopefully a better picture.

Dave

Archangel
- 31st May 2010, 19:20
Nice job 3 badgers and . . . Your wife's cat? I wouldn't get too close to that bad boy (girl?) their reputation precedes them. You have made great progress in 4 months Dave, Now, what do you think about infrared illuminators for the tripod ?

LEDave
- 31st May 2010, 19:57
Hi Joe

Thanks for that.

I think it was the same Badger three times (47 photo's to be exact (48 including the cat)) and heaven know who's cat that was!


Now, what do you think about infrared illuminators for the tripod ?

Mmm, not sure about that one Joe, wouldn't you need a camera that was sensitive to infra-red? Something like a security camera?

The camera I took the photo's with is probably the most basic digital camera still in use in the Northern hemisphere, are digital camera's sensitive to infra-red?

Dave

mackrackit
- 31st May 2010, 20:02
All digital cameras are IR sensetive.
Point you TV remote at the camera and see what happens.

LEDave
- 31st May 2010, 20:31
Blimey that was amazing, I never knew that would happen:):)

So what we're saying is that if we had enough IR-LED's I could take a picture without using the flash gun, is that right?

Dave