PDA

View Full Version : Problem with ports help plz



Mus.me
- 26th July 2009, 01:55
i donno where is the problem portb or a doesnt work to high many LEDs
example:

define osc 4
Include "modedefs.bas"

portb = 0
trisa = 0

main:
portb = %0111111
pause 100
portb = %10001101

goto main

doesnt work it works just if u toggle led by led


like:

high portb.1 or portb.2


need help please i tested it on many PICs th same problem????????????

Bill Legge
- 26th July 2009, 02:36
I think you have a few errors in your code:

1. If you want to flash the LEDs on PORTB, you must make PORTB an output:

TRISB = 0

2. The first pattern of LEDS only has 7 bit, make it eight:

PORTB = %01111111

3. At the end, just befor the loop ' GOTO Main' you need another PAUSE 100 of the LEDS will change too fast to see.

So the Main bit of your code should look like:

DEFINE OSC 4
TRISB = 0
PORTB = 0

Main:
PORTB = %10101010
PAUSE 100
PORTB = %01010101
PAUSE 100
GOTO Main

END

ChrisHelvey
- 26th July 2009, 03:59
Just FYI too:
The reason it works for you when using the "High" command, is that "High" automatically sets that port an output...so it works. Explicitly setting the port register as you did requires you to define the port as an output as Bill described.

Chris

Mus.me
- 26th July 2009, 04:33
I think you have a few errors in your code:

1. If you want to flash the LEDs on PORTB, you must make PORTB an output:

TRISB = 0

2. The first pattern of LEDS only has 7 bit, make it eight:

PORTB = %01111111

3. At the end, just befor the loop ' GOTO Main' you need another PAUSE 100 of the LEDS will change too fast to see.

So the Main bit of your code should look like:

DEFINE OSC 4
TRISB = 0
PORTB = 0

Main:
PORTB = %10101010
PAUSE 100
PORTB = %01010101
PAUSE 100
GOTO Main

END
THANK U FOR HELPING ME, IT WORKS GREAT I WAS WRITING SMALL LETTERS THATS WHY ,THIS MY CODE
FOR LED MATRIX 5X9 AND 4017 IC IT SHOWS ": A A "
DEFINE OSC 4
TRISB = 0
PORTB = 0
J VAR PORTB.5
Main:
PORTB.6 = 1
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 ' LETTER A
PAUSE 1
J = 0
PORTB = %00111111 'SPACE
PAUSE 1
J = 0
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 'LETTER A
PAUSE 1
J = 0
PORTB = %00111111 ' SPACE
PAUSE 1
J = 0
PORTB = %00110101 ' DOTS :
PAUSE 1

GOTO Main

END

JUST THINKING HOW I DO MY VARIABLES TO SCROLL TEXT AND SHOW MANY LETTERS ,THANK U BOTH AGAIN ,

Mus.me
- 26th July 2009, 22:27
THANK U FOR HELPING ME, IT WORKS GREAT I WAS WRITING SMALL LETTERS THATS WHY ,THIS MY CODE
FOR LED MATRIX 5X9 AND 4017 IC IT SHOWS ": A A "
DEFINE OSC 4
TRISB = 0
PORTB = 0
J VAR PORTB.5
Main:
PORTB.6 = 1
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 ' LETTER A
PAUSE 1
J = 0
PORTB = %00111111 'SPACE
PAUSE 1
J = 0
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 'LETTER A
PAUSE 1
J = 0
PORTB = %00111111 ' SPACE
PAUSE 1
J = 0
PORTB = %00110101 ' DOTS :
PAUSE 1

GOTO Main

END

JUST THINKING HOW I DO MY VARIABLES TO SCROLL TEXT AND SHOW MANY LETTERS ,THANK U BOTH AGAIN , hope someone can help

Mus.me
- 27th July 2009, 22:34
i wrote this instead the code above but i have problem with portb.5 and .6 not working ???
DEFINE OSC 4
TRISB = 0
PORTB = 0
TXT VAR BYTE
SR VAR WORD
J VAR PORTB

Main:
LOOKUP SR,[1,%00100001,%0,%00111111,%0,%00110101,%0,%00101010 ,%0,%00100000,%0,%00111111,%0,%00110101_
,%0,%00101010,%0,%00100000,%0],TXT
FOR TXT = 0 TO 18

J = TXT
PAUSE 100

NEXT TXT
GOTO Main

END

Archangel
- 27th July 2009, 23:57
Hello Mus.me,
Please tell us which PIC you are using, as each is a little different, so WE may look into it's data sheet. Your code looks like it will work BUT the unknown is if your PIC has analog stuff on portB, which you have not disabled.

Mus.me
- 28th July 2009, 00:43
Hello Mus.me,
Please tell us which PIC you are using, as each is a little different, so WE may look into it's data sheet. Your code looks like it will work BUT the unknown is if your PIC has analog stuff on portB, which you have not disabled. THANKS JOE ,IM USING F84 NOW I CHANGED SOME WIRES IT WORKS, BUT IM STILL FIGHTING WITH VARIABLES ,

THIS CODE IT WORKS
DEFINE OSC 4
TRISB = 0
PORTB = 0
J VAR PORTB.5
Main:
PORTB.6 = 1
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 ' LETTER A
PAUSE 1
J = 0
PORTB = %00111111 'SPACE
PAUSE 1
J = 0
PORTB = %00100001 '
PAUSE 1
J =0
PORTB = %00111010 '
PAUSE 1
J = 0
PORTB = %00100001 'LETTER A
PAUSE 1
J = 0
PORTB = %00111111 ' SPACE
PAUSE 1
J = 0
PORTB = %00110101 ' DOTS :
PAUSE 1

GOTO Main

END

I WANT TO USE VARIABLES
EXAMPLE


DEFINE OSC 4
TRISB = 0
PORTB = 0
J VAR PORTB.5
A VAR BYTE
B VAR BYTE
C VAR BYTE
D VAR BYTE
E VAR BYTE
F VAR BYTE
G VAR BYTE
H VAR BYTE
I VAR BYTE
Main:
PORTB.6 = 1
PORTB = A
PAUSE 1
J =0
PORTB = B
PAUSE 1
J = 0
PORTB = C
PAUSE 1
J = 0
PORTB = D
PAUSE 1
J = 0
PORTB = E
PAUSE 1
J =0
PORTB = F
PAUSE 1
J = 0
PORTB = G
PAUSE 1
J = 0
PORTB = H
PAUSE 1
J = 0
PORTB = I
PAUSE 1

GOTO Main

END
or like this

DEFINE OSC 4
TRISB = 0
PORTB = 0
TXT VAR BYTE
K VAR BYTE
J VAR PORTB
PORTA = 1
TRISA = 1

LOOP:
'IF PORTA.4 = 0 THEN GOTO MAIN
'LOOKUP K,[],TXT
FOR TXT = 1 TO 10
READ TXT,K
J = K
PAUSE 1
NEXT TXT
GOTO LOOP
END
DATA @ 1,%01101011,%01010101,%01101011_
,%01010101,%01101011,%01010101,%01101011_
,%01010101,%01101011,1


i've done PORTB.1 to 05 outputs to LEDs anoides , and ic 4017 to 9 cathodes and PORTB.0 pulse to 4017 clock and PORTB.7 to 4017 reset, i hope u understand and tell me ur ideas about the variables thanks.

mackrackit
- 28th July 2009, 01:57
PORTB = %00100001 ' LETTER A
no good when you later have
PORTB = A

Try....


A VAR BYTE
A = %00100001
PORTB = A

Mus.me
- 28th July 2009, 03:24
portb = %00100001 ' letter a
no good when you later have
portb = a

try....


a var byte
a = %00100001
portb = a

sorry i didnt explaine good my code
example the letter a is this

portb = %00100001 'letter a 1/3
pause 1
j =0
portb = %00111010 '" 2/3

pause 1
j = 0
portb = %00100001 ' " 3/3
pause 1
j = 0

each letter has 3 lines of 5 leds

Archangel
- 28th July 2009, 03:49
Hi Mus.Me,
2 things,
<b>first </b>Use Code Tags, Please.
You do this by writing the word" code "in between square brackets[write it here ] before your code, and after your code you put /code again in between square brackets, like so [/code]
<b>second</b> thing, what was the PIC you were having trouble with before?
Look at these links:
http://www.picbasic.co.uk/forum/showthread.php?t=11263
http://www.picbasic.co.uk/forum/showthread.php?t=10834
16F84 is a good fit for you right now, no extra distractions, "fighting with variables"? Oh, I see what you are saying . . .

Mus.me
- 29th July 2009, 04:56
thank u joe for help i will do it right this time lol

Archangel
- 29th July 2009, 09:23
thank u joe for help i will do it right this time lol
Great ! How's that code coming ?

wbubel
- 30th July 2009, 18:16
I have a weird PORTA problem. I set PORTA Bit 7 to digital input. The pin is pulled up with a resistor to VCC. When I first start the PIC after programing and release from reset, PORTA Bit 7 is at logic low causing my PIC to enter a branch to clear EEPROM and STOP. When I start the PIC again the program behaves normally.



DEFINE OSC 4 'Define the Osc to 8 MHz

asm
bsf OSCCON, SCS1 ; 1x = Internal Block
bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
bcf OSCCON, IRCF0 ; 001=0125 000=0032
MSTABLE010 btfss OSCCON, IOFS
bra MSTABLE010 ; wait until Oscillator is stable
endasm
data @0,0 'Initialize location 0 on eeprom to zero
LED2 var PORTB.2 ' LED
cntr var word
FET var PORTA.0
TRISA = %01000000 ' Set PORTA port 2 and 7 to input, 0, 3-6 ,8 Output
TRISB = %00000000 ' Set PORTB to all output
PORTB = %00000100 ' Clear PORTB, and set B2
PORTA = %01000000 ' Clear PORTA
led2 = 1
read 0,cntr 'read location 0 or eeprom
FET = 0
if (PORTA.7 = 0) then
pause 255
If (PORTA.7 = 0) then
write 0,0 'reset eeprom to 0 when port A Bit 7 has been forced to 0
Stop
else
Endif
else
endif
Main:
led2 = 0
pause 64
led2 = 1
if (cntr < 10) then
Pause 255 'slow blink under ten cycles
pause 255
else
Pause 64 'fast blink over 10 cycles
endif
cntr = cntr + 1 'increment cntr
write 0,cntr 'write new cntr value into eeprom
if (cntr <= 20) then goto main
FET = 1 'Shut down RF Current
' cntr = 0
stop
goto main
Stop

End

Though this is not a show ender it is bothersome.

mackrackit
- 30th July 2009, 18:28
A lot of PICs have analog on portA. If the one you are using shutting the ADC off may help.
Go to the FAQ section and look for a thread about portA not working.

wbubel
- 30th July 2009, 19:13
I disabled the A/D converter ADCON0 = 0, but the problem remains. Strange.

mackrackit
- 30th July 2009, 19:31
What PIC are you using?

wbubel
- 30th July 2009, 19:34
I am using the 18F1220 PIC.

mackrackit
- 30th July 2009, 19:44
Check the data sheet but if I remember correctly ADCON1 is the register to set on that PIC.
ADCON1 = %01111111
makes all digital.

wbubel
- 30th July 2009, 20:18
Check the data sheet but if I remember correctly ADCON1 is the register to set on that PIC.
ADCON1 = %01111111
makes all digital.

Setting ADCON1 makes no difference. Always on the first 'release from reset' it misbehaves.

mackrackit
- 30th July 2009, 20:28
Hmmm.
How are the configs set?

wbubel
- 30th July 2009, 20:30
I finally found the solution. You cannot clear PORTA
when I removed the code
'PORTA = %01000000 ' Clear PORTA
It worked on the first 'release from reset'. Now all I need is to indivually clear each bit.

wbubel
- 30th July 2009, 20:37
How's this for Spaghetti Code

PORTA.1 = 0 :PORTA.2 = 0 :PORTA.3 = 0 :PORTA.4 = 0 :PORTA.5 = 0 :PORTA.6 = 0

mackrackit
- 30th July 2009, 20:37
Great!
I saw you configs and was wondering about the OSC setting.
But if it is working...

mackrackit
- 31st July 2009, 00:19
How's this for Spaghetti Code

PORTA.1 = 0 :PORTA.2 = 0 :PORTA.3 = 0 :PORTA.4 = 0 :PORTA.5 = 0 :PORTA.6 = 0
A friend of mine writes code that way. Here is a mild sample.
http://www.picbasic.co.uk/forum/showthread.php?t=5407
After you do it that way for awhile it begins to make sence.

Bruce
- 31st July 2009, 01:04
Boat-load of errors in wbubels code Dave.

Got an E-Beer ready for the first one to fix em all & explain in detail why...;o}

mackrackit
- 31st July 2009, 01:24
Boat-load of errors in wbubels code Dave.

Got an E-Beer ready for the first one to fix em all & explain in detail why...;o}

But he said it was working :eek:
I was planning on going through it when I get back to the shop. A phone and traveling is not the best place to write and or fix code.

Maybe some one will else will get that beer :(

Archangel
- 31st July 2009, 02:19
HiYa wbubel,
PortA = %01000000 means portA.6 is going high when port is made an output, so if it crosses that place in space time while the PIC is initializing you will see PortA.6 output high. You want to set PortA.6 as zero and do it before you set the tris register to input or output so when it becomes an output or input the latch register is set in a known state, setting it as 1 does not enable pullups or anything like that, so you should have:


PortA = %00000000 ' set port latches low
TrisA = %01000000 ' make RA6 input

You ever watched an old mechanical slot machine? Figure your registers are going like that until the pic boots and settles into the default mode, usualy 11111111, then it follows your code.

Archangel
- 31st July 2009, 03:25
DEFINE OSC 4 'Define the Osc to 8 MHz

asm
bsf OSCCON, SCS1 ; 1x = Internal Block
bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
bcf OSCCON, IRCF0 ; 001=0125 000=0032
MSTABLE010 btfss OSCCON, IOFS
bra MSTABLE010 ; wait until Oscillator is stable
endasm
data @0,0 'Initialize location 0 on eeprom to zero
LED2 var PORTB.2 ' LED
cntr var word
FET var PORTA.0
'PORTB = %00000100 ' Clear PORTB, and set B2
PortB = %00000000 ' clear port latch bits
'PORTA = %01000000 ' Clear PORTA
PortA = %00000000 ' Clear PortA latches
'TRISA = %01000000 ' Set PORTA port 2 and 7 to input, 0, 3-6 ,8 Output
TRISA = %10000100 'Set PORTA port 2 and 7 to input, 0, 3-6 ,8 Output
TRISB = %00000000 ' Set PORTB to all output
led2 = 1 ' PortB.2 high LED on

read 0,cntr 'read location 0 or eeprom
FET = 0 ' PortA.0 Low
if (PORTA.7 = 0) then pause 255 ' pause 255 milliseconds
If (PORTA.7 = 0) then write 0,0 'reset eeprom to 0 when port A Bit 7 has been forced to 0


Main:
led2 = 0 'PortB.2 Low LED off
pause 64 ' very strange choice of pause 64 milliseconds
led2 = 1 ' LED on
if (cntr < 10) then
Pause 255 'slow blink under ten cycles cycles of what ?
pause 255 ' why this duplicate pause is good for something like 65535 ms
else
Pause 64 'fast blink over 10 cycles cycles of what ?
endif
cntr = cntr + 1 'increment cntr
write 0,cntr 'write new cntr value into eeprom
if (cntr <= 20) then goto main
FET = 1 'Shut down RF Current
' cntr = 0
'stop stop stops all brain activity how can it goto main?
goto main
'Stop

End

Here is your code with comments . . .changes

Mus.me
- 31st July 2009, 23:57
i need help i've tryed this code and when i add more text in ldata var it says error enable to fit ldata variable, and i changed ldta to var bit but it shows all LDEs on how can i fix this problem to add more scrolling text please help



DEFINE OSC 4
TRISA = %00000
TRISB = %00000000

column var byte
dchange var byte
scan var byte
scroll var byte
ldata VAR BYTE [59] when i change to bit it shows all leds on?
START:
CLEAR
ldata [0] = %11111
ldata [1] = %11111
ldata [2] = %11111
ldata [3] = %11111
ldata [4] = %11111'END OF CLEAR
ldata [5] = %01000
ldata [6] = %01010
ldata [7] = %00010 ' S
ldata [8] = %11111 '_
ldata [9] = %00000
ldata [10] = %11011
ldata [11] = %00000 'H
ldata [12] = %11111
ldata [13] = %00001
ldata [14] = %11010
ldata [15] = %00001 'A
ldata [16] = %11111
ldata [17] = %00110
ldata [18] = %01010
ldata [19] = %01100 'Z
ldata [20] = %11111
ldata [21] = %11111
ldata [21] = %00001
ldata [22] = %11010
ldata [23] = %00001 'A
ldata [24] = %11111
ldata [25] = %11111
ldata [26] = %00000
ldata [27] = %11101
ldata [28] = %11011
ldata [29] = %00000 'N
ldata [30] = %11111
LDATA [31] = %00000
LDATA [32] = %01110
ldata [33] = %10001 'D
ldata [34] = %11111
ldata [35] = %11111
ldata [36] = %11111
ldata [37] = %00000
ldata [38] = %11101
ldata [59] = %11011
ldata [39] = %11101
ldata [40] = %00000 'M
ldata [41] = %11111
ldata [42] = %00000
ldata [43] = %01111
ldata [44] = %00000 'U
ldata [45] = %11111
ldata [46] = %01000
ldata [47] = %01010
ldata [48] = %00010 ' S
ldata [49] = %11111
ldata [50] = %11111
ldata [51] = %11001
ldata [52] = %10110
ldata [53] = %01101
ldata [54] = %10110
ldata [55] = %11001 'HEART
ldata [56] = %11111
ldata [57] = %11111
ldata [58] = %11111
ldata [59] = %11111 'SPACE





LOOP:
FOR scroll = 0 TO 54
FOR scan = 0 TO 59
PORTB = 1
FOR column = 0 TO 7
PORTA = ldata [column]
PAUSE 1
PORTB = PORTB * 2
NEXT
NEXT
FOR dchange = 0 TO 59
ldata [dchange] = ldata [dchange+1]
NEXT
NEXT
GOTO START
END

mackrackit
- 1st August 2009, 00:16
Which PIC are you using? It might be full.
Start on post #11
http://www.picbasic.co.uk/forum/showthread.php?t=10381

Mus.me
- 1st August 2009, 00:42
Which PIC are you using? It might be full.
Start on post #11
http://www.picbasic.co.uk/forum/showthread.php?t=10381

im using 16f84 but when i change ldata var byte to ldata var bit it complier but it doesnt work it keeps blinkin leds,i think the problem in the code and scrolling, and pic16f84 it takes 1024 words i think but i see just between 258 to 300 word, it works when i change to var bit but it doesnt scroll it shows LEDs blinkin and all off them on ????

AND I WANT TO USE DATA EPPROM INSTEAD THE VARIABLE ldata IF SOMEONE CAN HELP ME

Archangel
- 1st August 2009, 03:17
im using 16f84 but when i change ldata var byte to ldata var bit it complier but it doesnt work it keeps blinkin leds,i think the problem in the code and scrolling, and pic16f84 it takes 1024 words i think but i see just between 258 to 300 word, it works when i change to var bit but it doesnt scroll it shows LEDs blinkin and all off them on ????

AND I WANT TO USE DATA EPPROM INSTEAD THE VARIABLE ldata IF SOMEONE CAN HELP MEHi Mus.Me,
OK the 16F84 does not have enough code space to do that, it will fit into a 16F628A, BUT ah say BUT, you will have to reorder the listing of the variables to avoid a bank error from PBP, and no it is not the crossing boundries error either. So I did like so:


ldata VAR BYTE[59] 'when i change to bit it shows all leds on?
column var byte
dchange var byte
scan var byte
scroll var byte

EEprom is not so hard to do . . .why not use a lookup table ?


for index = 0 to 19
'ldata 0 1 2 3 4 5 6 7 8 9 10 11 12 . . . . .
lookup index,[31,31,31,31,31,8,10,10,31,0,27,0,31,1,26,1,31,6,2, 12]ldata
Portb = ldata
next index

Mus.me
- 2nd August 2009, 21:51
thank u joe for the help i will try it out and change to 628.