How do i let an output pin equal a variable

Hi, currently im making a binary clock as a proof of concept for a bigger clock project(gps time update,elaborate display etc etc)

currently i am reading the time in from a ds1307 and converting the values to binary.

once binary i can display the minutes with let pins = minutes

but the hours are displayed on portc pins 0,1,6,7 for bits 1,2,4,8 respectivley, as hours are stored in b1 im assuming i can address each bit via bit7,bit8 ,bit9,bit 10.

how can i do this :

let portc 0 = bit7
let portc 1 = bit9
let portc 6 = bit10
let portc 7 = bit11


sorry for the long post.

thanks.
Lachlan
 

westaust55

Moderator
You do not say which PICAXE chip you are using . . . .
but 28X1/40X1 seems likely

can you change the order of the bits in b1 to use bits 7, 8, 9 and 10?
then, untested but you could try this approach:

SYMBOL TRIC = 135
SYMBOL PoorTC = 7

b5 = b1 AND %00001100 * 8 ; move bits 9 and 10 into top 2 bits of b5
b5 = b1 AND %00000011 OR b5 ; now put bits 7 and 8 into low 2 bits of b5

POKE TRIC, %11000011 ; 0 = output, 1 = input
POKE PoorTC, b5 ; put b5 to portC,


You could make reference to my PICAXE variable map and SFR control details from here as well:
http://www.picaxeforum.co.uk/showthread.php?t=11514
 
Last edited:
thanks guys.

i ended up using if else option. it seems a bit easier, but im a bit unimpressed there is no simple way to set an output with a binary bit. seems like a fairly low level instruction.
 

westaust55

Moderator
The IF....THEN method will take about twice the memory of the POKE method.

Even if one were to try machine code and a raw PIC chip, with your requirements, there would be no simple command to put assorted bits directly to a port.

It is a case of understanding how microcontrollers and microprocessors work.
Things you will/may learn about in time
 

hippy

Ex-Staff (retired)
There may well be easier ways than IF-ELSE but you don't say which PICAXE you are using. On the 28X2 it's as simple as -

let pinC.0 = bit7
let pinC.1 = bit9
let pinC.6 = bit10
let pinC.7 = bit11

Any project or product requires design to balance the hardware against the PICAXE chosen and the commands it supports to match the specification. Each will influence the other; hardware may dictate what PICAXE is chosen, PICAXE chosen will define what hardware options there are, hardware will dictate what software is required, software commands may dictate particular hardware. On top of that you will have cost and possible skill constraints.

Amongst all those possibilities will be options which are ideally or better suited and others which are less so. If you end up with a less than ideal design you have to jump through hoops to make things work when they would be easier otherwise.

It's easy to go from idea to implementation but then run into problems and difficulties; lack of program memory or variables, I/O mapping far from being ideal, difficulty in controlling I/O. Ideally development should be along the lines of product specification, functional specification, architectural design, prototyping, implementation and testing, with each stage weighing up the pro's and con's of possibilities and comparing and contrasting options at each stage, and it's a looping and iterative process as well as; discoveries ( of problems or things which may be beneficial ) feeding-back into a re-design which is better. For experienced developers the process is largely second nature rather than a set of formal rules.

Being unimpressed by a particular PICAXE or its capabilities is a bit like being unimpressed that a family saloon doesn't perform as well as an F1 racer on the track. Some PICAXE's, just like cars, don't support some things which are desirable because of limitations, there's just no way to support all that may be desirable with what's available at the price people will pay so compromise has be had.

All of us have gone down the path ( or will ) with a project which hits a dead-end or winds up with difficulties and it's realised that there could have been a better design, and that complexity and difficulty comes as a consequence of the path we followed. It's all part of the learning experience.
 

Dippy

Moderator
And you'll find that applies to most uControllers and every designer in existance.

There are limitations with every device ever invented and every compiler I've seen has something where you wish "if only it could do..." .

There's a phrase: "Horses For Courses".
As you get more experienced you'll be able to choose your horse more easily ;)
 
Yes. I would totally agree with that statement.

as stated earlier, i was echoing out using the let pins = minutes, which surprised me that i couldnt do this with a single pin and bit.

does the let pinC.0 = bit7 work on the 40x1 ?
 

BeanieBots

Moderator
Interestingly I had reason to try this out today but with no joy.

An assignment such as "LET pinC.0=bit0" does not work for me using a 28X2.
All it does is render the pin as an input.

Tried several variants on the theme all with the same result.
Tried with PE 5.2.9 & 5.2.7, same result.

Hippy?
 

hippy

Ex-Staff (retired)
Did you issue a "dirC.0=1" to make it an output ? Simply setting pinC.0 won't automagically make the pin an output.

#Picaxe 28X2
#No_Data
#No_Table

dirC.0 = 1
Do
pinC.0 = bit0
bit0 = bit0 ^ 1
Pause 1000
Loop
 
on another note, i just received a 40x2 picaxe for my next project.

i need 25 or so outputs, can all the pins on the 40x2 be used for all applications(of course with some exceptions).
 
Top