Page: ...
*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
I just finished soldering up my 'Hyperlights'. Red, Green, and Blue Luxeon PIC Uber poi cool






Non-Https Image Link



Non-Https Image Link

Non-Https Image Link






More images with the Luxeons running here

Cake or Death?


Jomember
517 posts
Location: Sheffield, England


Posted:
Hrm...



Maybe your configuration bits need changing? Or your delays need making longer?



Hard to say from just a little description... confused



If you have the transistors wired up like I said earlier, the problem probably lies somewhere in the programming.



good luck



Jo.

Educate yourself in the Hazards of Fire Breathing STAY SAFE!


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
ive redone the soldering works. now it's something different... the lights just stays off. i dunno if this is better or worse...

anyways, the hardware seems OK now... there's seriously no way that i've missed something. When I connect the emmiter to the collector the leds turn on... well... im gonna try and try to see if I fix it with software...



when the first light starts blinking due to correct programming im gonna run 3 blocks straight, cuz of enthousiasm smile



can any of you be of any assistent with a simple testprogram?




Non-Https Image Link


above you can see my hardware... should be ok. right?



*edit edit*

meanwhile I was stuck with the program, i finished up my design a bit... here are 2 pics:


Non-Https Image Link



Non-Https Image Link



EDITED_BY: anonomatos (1121111014)

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Wow, nice - I'm impressed!! How wide / tall is that thing?



I believe your hardware should link up like this (if you're using an NPN transistor):




Non-Https Image Link

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
5.5cm width, 6cm high. size of a monkey fist i guess... and the size and weight is perfect to use in a sock smile



as far as I can see my circuit is the same as the one on your picture, right?



still... can you be of any assistance with the code?

On my PIC-programmer I have this experiment-board with led lights. My program worked fine there, but in the poi it's does nothing.

I don't need a copy of your code. Just a complete code to test lights on port RB04, 05 and 06.



would one of you mind to build that code for me? from there on i can experiment further, but I need some sort of basic. please... ubbangel

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Email me the code and I'll look over it... Jon at geekops dot co dot uk

It's probably some dodgy register setup smile

Cake or Death?


Brian:-)BRONZE Member
stranger
37 posts
Location: London, United Kingdom


Posted:
Hyperlite,
Sorry to criticize but your diagram shows a PNP transistor. The arrow should be pointing away from the junction and to ground. Other than that it is correct.

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
*click* send smile

hope you can fix it... im pretty much out of guesses considering programming :-/

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
This is the code I used to first test my circuit. I've changed it so it should work on a 16F627 (The simulator didn't complain). I also put some swapf commands in so the output will be on the right ports for you.



It'll count in binary, changing every second.



Code:
;**************************************************************************

; 4bit.ASM

;

; This is a simple 4 bit counter, writing the result to PORTB...

;

;

;**************************************************************************



LIST P=16F627, R=DEC

__CONFIG _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_OFF & _CP_OFF & _INTRC_OSC_NOCLKOUT & _LVP_OFF

include "P16F627.inc"



;--------------------------------------------------------------------------

; Variables

;--------------------------------------------------------------------------



Ram EQU h'20'



Count EQU Ram+0

timer_local EQU Ram+1







;--------------------------------------------------------------------------

; Program Code

;--------------------------------------------------------------------------



ORG 0 ;reset vector

Start call Init ;Initialise hardware



Reset clrf Count ;Reset Count

Loop swapf Count,1

movfw Count ;Move Count into W

movwf PORTB ;Write W to PORTB



call Wait1Second ;Call the 1 second subroutine



swapf Count,1

incf Count,f ;Count = Count + 1



movlw d'16' ;W = 16

xorwf Count,w ;W = 16 XOR Count

btfss STATUS,Z ;Check the Z flag in the STATUS register

;Is it set?

goto Loop ; No, so Count <> 16 - keep counting

goto Reset ; Yes, so Count = 16 - reset counter







;--------------------------------------------------------------------------

; Subroutines

;--------------------------------------------------------------------------



;*****Init - set up all ports, make unused ports outputs



Init clrf PORTA ;all of porta low

clrf PORTB ;all of portb low



bsf STATUS, RP0 ;change to bank1

bsf PCON, 3 ;set INTOSC to 4Mhz

clrf TRISA ;all of porta outputs

clrf TRISB ;all of portb outputs

bcf STATUS, RP0 ;back to bank0



return





;*****Timing routines - general purpose delays (4MHz clock)



Wait1ms movlw d'250' ;initial value - tweak if req.

nop

loop1ms addlw d'255' ;dec w

btfss STATUS, Z ;Zero flag set?

goto loop1ms ;No, keep looping

return ;1ms done



WaitNms movwf timer_local ;timer_local=w

loopNms movlw d'248' ;revised value due to extras

call loop1ms ;248*2+2=994

goto $+1 ;+2

decfsz timer_local,f ;dec loop variable - is it Zero?

goto loopNms ;No, keep looping

return ;Nms none



Wait1Second movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

goto WaitNms ;





END ;Stop assembling here




You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
it's not working... this is what assembler spits out:



22 errors



Warning[216] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 11 : Radix superceded by command line.

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_WDT_OFF)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_PWRTE_OFF)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_BODEN_OFF)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_MCLRE_OFF)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_CP_OFF)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_INTRC_OSC_NOCLKOUT)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 13 : Symbol not previously defined (_LVP_OFF)

Error[105] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 15 : Cannot open file (Include File "P16F627.inc" not found)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 36 : Symbol not previously defined (PORTB)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 46 : Symbol not previously defined (STATUS)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 46 : Symbol not previously defined (Z)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 59 : Symbol not previously defined (PORTA)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 60 : Symbol not previously defined (PORTB)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 62 : Symbol not previously defined (STATUS)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 62 : Symbol not previously defined (RP0)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 64 : Symbol not previously defined (PCON)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 66 : Symbol not previously defined (TRISA)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 68 : Symbol not previously defined (TRISB)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 70 : Symbol not previously defined (STATUS)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 70 : Symbol not previously defined (RP0)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 81 : Symbol not previously defined (STATUS)

Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\BIT4.ASM 81 : Symbol not previously defined (Z)





Would you mind taking another look to the code?



*EDIT*



I forgot to use the include file... GUESS WHAT



IT'S WORKING! IT'S WORKING!



WHAAAAAAAAAAAAAAAAAAA!



*JUMPS AROUND*



hug hug hug hug



THANK YOU SOOOOO MUCH! biggrin

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Nice one.. now lets see some pics of those things spinning! smile

Cake or Death?


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
I guess you'll be wanting to know how to do PWM now? wink

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
first i'll be fixing some minor hardware thingies (i still got a wrong resistance in the circuit) and finalize design (the sock is still 'sloppy', making only a slight part visible... need something to hold the sock a bit wider so more of the 'cone' is lighted)

THEN i wanna know how to do PWM wink if you have some tips already: go ahead... somewhere in the evening ill be looking to the code again smile

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Sssshhhhh... it's a secret! He's learning too quick.. all those months I slaved away at my poi, and he's half way there already!! hehe, nah, props to you anonomatos - looking forward to seeing what you come up with.

Cake or Death?


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
I think some pseudocode will do for now. That way you'll have an idea what the assembler is doing.



This fades one LED on and off repeatedly. It's pretty simple to add other LEDs. Delays can wait till you've got an assembler version that's optimised.



Code:


01 pPos = 0 ;Position in pulse

02 oPos = 128 ;Position in pulse to turn on LED

03 cDir = 1 ;Direction of change, 1 = off to on, 0 = on to off

04

05 while pPos < 128 : ;a pulse is made up of 128 repetitions of this loop

06 pPos = pPos + 1 ;

07 if pPos = oPos: ;when the loop position = when you want the LED to come on,

08 turn on LED ;turn on the LED.

09

10 turn off LED ;the pulse loop is completed, so the LED can be turned off

11

12 if cDir = 1: ;if the LED should be getting brighter,

13 oPos = oPos - 1 ;make the LED come on earlier in the pulse (decrease oPos by 1)

14 if cDir = 0: ;if the LED should be getting dimmer,

15 oPos = oPos + 1 ;make the LED come on later in the pulse (increase oPos by 1)

16

17 if oPos = 0: ;if the LED on position in the pulse has decreased so it's at the beginning,

18 cDir = 0 ;swap the direction of change so the position increases, making the on time shorter.

19 if oPos = 128: ;if the LED on position in the pulse has increased so it's at the end,

20 cDir = 1 ;swap the direction of change so the position decreases, making the on time longer.

21

22 goto line 05



EDITED_BY: polarity (1121200039)

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
im looking a bit at the testcode you gave me, and still haven't figured out what does what exactly. i figured out delays, that's one thing...



but when I look at that PWM code it's like chinese for me. i'm completely clueless where to put it in the .asm file.



do any of you have a tutorial or something? i've seen several (test)codes and after most lines there's an explanation (like the one polarity has written)... but even those explanations don't get me far:

"reset vector adress"

"Disable Comparator module's"

"Write the option register"

etc.

etc.



i found a german site https://www.sprut.de/electronic/pic/assemble/befehle.html#befehle

but my german is a tad bit bad frown



is there any tutorial like that one but in english?

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
Sorry, forgot to comment it. Pseudocode won't run. It's just a way of writing down what's going on so it's easier to understand.



*edited*



I'll try and draw some diagrams of what's going on, and put them on my LEDPOI site.



Might be an idea to find some basic programming tutorials, so you get the hang of loops and conditionals.

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
For a basic uC (micro-controller) tutorial, try this.

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
i think that the tutorial is just about EXACTLY what i needed smile



thnx a bunch, ill be asking some more stupid questions in a day... first ill read the tutorial wink



*edit*

so funny, ive re-read the last 2 pages or so of this thread... and realised that just less than 3 weeks ago i had seriously no idea where to start and was asking the most stupid questions you can imagine. and now i have a working programmable poi cool

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Yip, it's most impressive! A lot of the learning involved in knowing what to do can be dealt with very quickly (like most things in life) if you're got someone to say 'no, don't be silly, try this'.. I only wish I'd had someone like me (now), or polarity to pester and say 'I don't get it, how do I do this smile

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
okay... so first question:



movlw 0x80

movwf PORTB

movlw 0x40

movwf PORTB



so this places the value 0x80 in the work register. then places the value 0x80 from the work register in the instruction register, directly sending it to PortB and opening a certain port (RB01-RB07)... but how does the PIC know what port to open? It's has something to do with the value '0x80' for example... but where to I find the info on what does what? Searched the datasheet but can't find it :S



*edit*



so this meaning that a port can only but fully open (1) or fully closed (0), right?
EDITED_BY: anonomatos (1121256003)

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
The port is digital so yes, it's either 1 or 0 (which is basically +ve supply voltage or 0v i.e. ground).

The values you've got there are hex codes. Hex is just another way of counting numbers, only instead of counting;

01,02,03,04,05,06,07,08,09,10,11,12,....

you count;

01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,....

So 80 is eqivalent to 128, and 40 is equivalent to 64. Now comes the clever part, you can also represent numbers in binary which is what your computer uses. Binary is a series of ones and zero's which represent normal numbers. They are generally stored as bytes - that is, 8 bits (one's and zero's) make a byte:

| 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
--------------------------------------
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | = 1
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | = 2
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | = 3
...
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | = 40
...
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | = 80
...

You add up the numbers at the top where you have a 1 in the table below. I've given 1,2,3 and then the values you gave in your last post.

So when you set 0x40, it turns RB6 to 1 which turns on whatever LED you have connected there. Set it to 0x80 and you turn on RB7...

Hope that clears it up?

Cake or Death?


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
Most people count in base 10, meaning we have 10 characters to use in numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), and columns are worth 10 the value of the one to their right. So we have the following column values:

etc. | 1000 | 100 | 10 | 1 |

4256 = (4 * 1000) + (2 * 100) + (5 * 10) + (6 * 1)


Hex (hexadecimal) is base 16, so there are 16 characters used for counting, (0-9 then A-F) and each column is worth 16 more than the one to the right.

etc. | 4096 | 256 | 16 | 1 |

If you use hex enough you learn to associate the correct values to the letters (A=10, B=11, C=12, D=13, E=14, F=15) and it gets a little easier to work with, but it's still harder to work with than decimal or binary.

E3AD = (14 * 4096) + (2 * 256) + (10 * 16) + (13 * 1) = 58285 in decimal

Binary is base 2. only two characters, and each column worth 2 times the one to the right.

etc. | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

10011010 = (1 * 128) + (0 * 64) + (0 * 32) + (1 * 16) + (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1) = 154 in decimal

Computers and microcontrollers are classified by the number of bits they use per byte. 16Fxxx are 8bit, so they can count up to 255 (or 256 different values, including the 0), by having a 1 in each of the 8 columns, or bits.

Try adding two numbers that give a result higher than 255, and the value will reset to 0, then give the amount by which it's over 255. A flag is set in the chip though, to say that a calculation went over 255.


Hex is convenient for providing a shorthand for expressing binary values, as 2 columns in hex is the same as 8 bits in binary. Other than that it's just difficult to use.

If you're working with ports then you're best off using binary, like this:

MOVLW b'01000000'
MOVWF PORTB
MOVLW b'10000000'
MOVWF PORTB

That way it's easier to see where in the port things are going on or off (this turns on just PORTB,6 then just PORTB,7, the bits are numbered with the highest value, 7, at the left and the lowest, 0, at the right).


If you're just counting something, like how many times you've run through a loop, then you can use decimal, by puting the number in quotes preceded by a 'd'.

MOVLW d'128'
MOVWF variable ;set the value of variable to 128


It doesn't matter to the program whether you use binary, decimal or hex, as the assembler just turns everything into hex for programming to the chip. You're better off using whatever number system suits you best.

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
okay... still dizzy with number floating around, but tonight i'll have another look. I couldn't find some codes in the datasheet, but realised i have to actually count to find it.

_EXTCLK_OSC EQU H'3FEF' (from a demo code i got with my programmer)

'h3fef'... can't find it in the datasheet, but i guess i have to 'translate' that sort of thingies to the correct language... right? Or im i missing the point?

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
That command just makes the label '_EXTCLK_OSC' a reference for the memory address '3FEF' (in hex) which is the configuration bit that turns the external oscillator on or off.

That souldn't need to be in the code, as all the name to memory address references are in the include file for the chip (where h'3FEF' is called _EXTCLK).


Configuration bits have to be programmed to select what functions are enabled on the chip, and what some of the multi function pins do.

The _CONFIG line from the 4bit counter test code I gave should be good enough for most programs, and by not using the external oscillator you don't need to build extra circuitry.

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
It was just an example of a configuration thingie... but now i understand even a little bit more...

bit by bit some of the puzzle pieces start falling together.

though i still have no idea how to write anything... but itll come in time smile



*edit*



ive been looking at the 'simple' pwm code on the wikipoi site of polarity... and there's alot of things i don't understand.

1. nowhere in the code i can find what port it opens... çept for portB, but not which one exactly

2. there's positions between 0 and 128 for the cycle, right? now i can't find in the code how it reads where it is and how it adds pulse width... prolly this 'incf cPos, 1 ;increase position counter' right?



and i have a question about this piece of code:

Loop movf cPos, 0 ;

subwf Red, 0 ;

btfsc STATUS, Z ;if cycle position = red period end

bcf PORTB, 0 ;turn off LED



it puts something in cPos... but what? the value 0? and then something in the work register. then status Z (what the hell is that Z-thing anyways?) is checked... if it's true the next line (turning of the led) is skipped... and thus moving through the cycle again? till it's false?



mh... i'm asking weird and loads of questions. but each answer is a little piece of the puzzle smile keep helping me plz biggrin




EDITED_BY: anonomatos (1121297537)

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
I've got some 16f627A pics but they don't seem to work. I keep getting this error:

Warning[216] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\NIEUWE MAP\1.ASM 11 : Radix superceded by command line.
Error[113] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\NIEUWE MAP\1.ASM 13 : Symbol not previously defined (_INTRC_OSC_NOCLKOUT)
Message[302] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\NIEUWE MAP\1.ASM 64 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\NIEUWE MAP\1.ASM 66 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\VELLEMAN\EXAMPLES\NIEUWE MAP\1.ASM 68 : Register in operand not in bank 0. Ensure that bank bits are correct.


It's the testprogram made by polarity i was gonna write... help?...

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


polaritySILVER Member
veteran
1,228 posts
Location: on the wrong planet, United Kingdom


Posted:
First line of the program is:



LIST P=16F627, R=DEC



The radix is the R=DEC part. This just means that the radix has already been set in the commands sent to the assembler program (when you do quickbuild), so it's redundant here. You could check to build options, to turn it off there. You should change the P= part to 16F627A.



The second error is probably caused by something in the .inc file. which should be 16f627A.inc You should also change it to _INTOSC_OSC_NOCLKOUT, which is the new version for the 627A.



The last 3 lines you can ignore. They always come up. They're just a warning to you to check that you're using the right memory bank.



bsf STATUS, RP0 ;change to bank1

bsf PCON, 3 ;set INTOSC to 4Mhz

clrf TRISA ;all of porta outputs

clrf TRISB ;all of portb outputs

bcf STATUS, RP0 ;back to bank0



The registers PCON, TRISA and TRISB aren't in memory bank 0, so it's just asking you to check that the code switches to bank 1 before you try to use them.





I'm going to the Glade festival for the weekend, where I'll be giving my LED poi their first outing biggrin Someone else'll have to follow up if there are any more problems between now and monday..

You aren't thinking or really existing unless you're willing to risk even your own sanity in the judgment of your existence.

Green peppers, lime pickle and whole-grain mustard = best sandwich filling.


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
I just had to change the _INTRC_OSC_NOCLKOUT into: _INTOSC_OSC_NOCLKOUT ... that was all smile
thnx!

second PluX unit is on it's way... then it's time to really start programming!

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Hello again. I've been through some tutorials and im starting to understand the very very first basic things. About registers and opening ports mostly.



Each time i learn something i look into the demo code and the test-code from polarity (see below). Ive cracked my head over that code but can't figure it out. It opens one port, the another one, then those 2 at the same time, then a third one, then opens 2 ports, then 2 different ports, and then all 3 ports at the same time. The only thing I can found that are written to port B is something like 'Timer' and 'Count'.



I would gladly appreciate if anyone can explain this code a bit... how does it work? I tried to remove a pause in the loop (after all 3 colors are turned on, it returns to the beginning of the loop, but pauses for about 1 second... not very charming when i'm poiing with it and it turns black for a second smile ). Apart from removing the pause im trying to understand how it works... of course. Im progressing very little at a time... but i will learn how to program it! (eventually rolleyes )



;**************************************************************************

; 4bit.ASM

;

; This is a simple 4 bit counter, writing the result to PORTB...

;

;

;**************************************************************************







LIST P=16F627A, R=DEC



__CONFIG _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_OFF & _CP_OFF & _INTOSC_OSC_NOCLKOUT & _LVP_OFF



include "P16F627A.inc"



;--------------------------------------------------------------------------

; Variables

;--------------------------------------------------------------------------



Ram EQU h'20'

Count EQU Ram+0

timer_local EQU Ram+1



;--------------------------------------------------------------------------

; Program Code

;--------------------------------------------------------------------------



ORG 0 ;reset vector

Start call Init ;Initialise hardware



Reset clrf Count ;Reset Count



Loop swapf Count,1

movfw Count ;Move Count into W

movwf PORTB ;Write W to PORTB





call Wait1Second ;Call the 1 second subroutine



swapf Count,1

incf Count,f ;Count = Count + 1



movlw d'16' ;W = 16

xorwf Count,w ;W = 16 XOR Count

btfss STATUS,Z ;Check the Z flag in the STATUS register



;Is it set?



goto Loop ; No, so Count <> 16 - keep counting

goto Reset ; Yes, so Count = 16 - reset counter



;--------------------------------------------------------------------------

; Subroutines

;--------------------------------------------------------------------------



;*****Init - set up all ports, make unused ports outputs



Init clrf PORTA ;all of porta low

clrf PORTB ;all of portb low



bsf STATUS,RP0 ;change to bank1



bsf PCON, 3 ;set INTOSC to 4Mhz



clrf TRISA ;all of porta outputs



clrf TRISB ;all of portb outputs



bcf STATUS,RP0 ;back to bank0



return



;*****Timing routines - general purpose delays (4MHz clock)



Wait1ms movlw d'250' ;initial value - tweak if req.

nop



loop1ms addlw d'255' ;dec w



btfss STATUS, Z ;Zero flag set?



goto loop1ms ;No, keep looping



return ;1ms done







WaitNms movwf timer_local ;timer_local=w



loopNms movlw d'248' ;revised value due to extras

call loop1ms ;248*2+2=994

goto $+1 ;+2

decfsz timer_local,f ;dec loop variable - is it Zero?

goto loopNms ;No, keep looping

return ;Nms none





Wait1Second movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

call WaitNms ;

movlw d'250' ;250mS

goto WaitNms ;



END

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
First, a little correction, you don't "open" a port, what you're doing is setting some of the bits of that port to 1 or 0. Picky I know, but while you learn how to code in assembly, you may as well learn the lingo wink

Okay, the next problem is your 1 second delay. Quickly looking through the code, you have a call the 1 second delay:

call Wait1Second ;Call the 1 second subroutine

if the bits of PortB that turn your LEDs on aren't set, then they won't be on for that second!

Cake or Death?


Page: ...

Similar Topics

Using the keywords [luxeon poi] we found the following existing topics.

  1. Forums > Luxeon Star LED, 660,000 mcd [7 replies]
  2. Forums > A Splendiferous LED, if you can afford it [5 replies]
  3. Forums > Luxeon LED Poi Pics [35 replies]
  4. Forums > Luxeon Poi... [241 replies]
  5. Forums > Single Colour Luxeon Poi, easier construction [10 replies]

      Show more..

HOP Newsletter

Sign up to get the latest on sales, new releases and more...