PDA

View Full Version : Problem runing my code



Mus.me
- 22nd November 2009, 20:53
im runing this code pic16f628a this is the code for lcd 7 segment with 74hc164,and when i add things like clock or other code it cuz delay and troubles to the lcd routine plz help i want to add my code here conter and clock and some thing else but i want to put them out o0f the lcd 7segment loop or label and dont cuz troubles or delay for lcd routines ...


@ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
DEFINE OSC 4


intcon = 0
vrcon = 0
CMCON = 7 '
Hundredths VAR BYTE
Seconds VAR BYTE
Minutes VAR BYTE
Hours VAR BYTE

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte
PORTA = %00001
PORTB = %11000000
TRISA = %00001
TRISB = %11000000
' im trying to add my code here loop: goto loop, and want the main: label stays workin its for the 7 segment
'and i want to add here clock to ???????and other problem my code has delays of pause 1000 and 2000,..
B0 = 0

loop:
b0 = b0 + 1
if b0 = 9999 then b0 = 0 ' here i will put delays in my code so it willl cuz 'problems to the main code .. delays digit blinkin very slow
GOSUB MAIN

MAIN:
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTB.0[index] = 1
PAUSEUS 999
PORTB=0
NEXT INDEX
return

END
data @0,3,159,37,13,153,73,65,31,1,9

Dennis
- 22nd November 2009, 21:34
Hi Mus.me

I think it would be helpful if you include a schematic showing how your LCD is connected so other will find it easier to help you :-)

Is it a serial LCD HD44xxxx or a 7-segment LCD?
Does it work standalone(not connected to the pic) ?
Does the LCD work if it directly connected to the PIC
Which ports is it connected to ?
The define statements helped me ;-) but I am using a 2x16 LCD but I do realize you may be using a 7 segment LCD



'LCD defines begin here
DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to
DEFINE LCD_EREG PORTD 'defines the port where E line is connected to
DEFINE LCD_EBIT 3 'defines the pin where E line is connected
DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 200 'delay in micro seconds
'END of LCD DEFINES


And maybe connect it as included diagram shows
in this post that I made (ignore the PIC model , just make sure that whatever port you use you have set if for input eg. TRIS PORTX=%11111111)
http://www.picbasic.co.uk/forum/showthread.php?t=12179

I apologize if I have read your post completely wrong :-(

Hope this helps

Kind regards
Dennis

Mus.me
- 22nd November 2009, 22:23
SORRY ITS JUST 7 SEGMENTS NOT LCD..this is the 7segment schema i did draw sorry i havnt draw it good but im sure thats enought to undersnd its normal 7seg working through 74hc164 shift register and 4 digit pins to the pic .atached them all to portb . it works fine with a counter like b0 = b0 +1 to 9999. but i cant add any pause or delay i need to findout how to run my program apart of the 7 segment routing or loop. <<<< ITS LIKE I HAVE A LED BLINK IN A LOOP AND I WANT TO WRITE MY CODE APART AND LET THE LED BLINKIN WITHOUT STOPING EVEN OTHER PROGRAME IS WORKIN AND HAS ITS DELAYS OR NO OR SOME ITS LIKE I WANT TO RUN 2 THINGS IN 1 TIME 2 LOOPS I DONNO IF TIMRERS WILL HELP OR WAT TO WITH THIS BLLODY THINGS LOL >>>>THIS 7SED GODE WORKS OK THE TOP 1 I POSTED BEFOR ISNT WORKING ANYWAY THANK U FOR HELP


@ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
DEFINE OSC 4


intcon = 0
vrcon = 0
CMCON = 7

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte

PORTA = %00000
PORTB = %11000000
TRISA = %00000
TRISB = %11000000

B0 = 0

loop:


MAIN:
''''''''HERE IN THIS LOOP I CANT WRITE PROGRAME WHICH HAS DELAYS.
'''''' ALL WAT I WANT IS TO LEAV THIS RUNING ITS ROUTING EACH PAUSEUSS999
''''''' I WANT TO PUT MY PROGRAME OUT OF THIS LOOP AND SEND WAT I WANT TO SEE ON THE 7SEGMENT TO B0 VAR
if btN = 0 then b0 = b0 - 1
if btm = 0 then b0 = b0 +1
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTB.0[index] = 1
PAUSEUS 999
PORTB=0
NEXT INDEX

GOTO MAIN

END
data @0,3,159,37,13,153,73,65,31,1,9

Mus.me
- 23rd November 2009, 12:24
i think none understands my quetion.i want to run like this code ..
i want both programes to run apart from each other its just example so i can write my programe like this plz help



main: ' i wa]nt this led to blink forever without any other delay or stops
high led
pause 100
low led
pause 100
goto main

loop: ' and i want this led1 to blink without any other delay or stop
high led1
pause 2000
low led1
pause 200
goto loop

Acetronics2
- 23rd November 2009, 13:28
i want both programes to run apart from each other


Hi,

With Pics ... You CAN'T do two things at the same time ( say totally independant things - excluding Peripheral use )

a Pic does ONE THING AT A TIME ... " Multitasking " just is doing a little part of a task, then a little part of another task, then ...... a little part of the first task, then ....

very quickly.

thats ALL !!!

For your LED Example ... you'd have to use a Pair of "555" as EXTERNAL peripherals, ( HPWM modules are too fast ) to drive your leds .

Alain

Mus.me
- 23rd November 2009, 13:38
Hi,

With Pics ... You CAN'T do two things at the same time ( say totally independant things - excluding Peripheral use )

a Pic does ONE THING AT A TIME ... " Multitasking " just is doing a little part of a task, then a little part of another task, then ...... a little part of the first task, then ....

very quickly.

thats ALL !!!

For your LED Example ... you'd have to use a Pair of "555" as EXTERNAL peripherals, ( HPWM modules are too fast ) to drive your leds .

Alain
o right thank u Acetronics for reply.check ur pm . it just confused me this 7 sgment it need the routine in main label each 1 ms, so if i put anythings has delays or like serin it cuz the 7seg delay and blinking slow thats im thinkin to define it like lcd or something to kepp the shift out runing each 1 ms .and do my programe works and has delayes,,,,,,,,,

Acetronics2
- 23rd November 2009, 14:07
Hi,

BUT ...

I think you could " re write " your project ... showing clearly what you want to do !!!

refresing your full display @ 200 Hz is not compulsory . 50/60 Hz is a classical value ... that leaves some time in between to do little other tasks ... while a digit is lit ...

You should Google around For the numerous ( ! ) alarm clock projects on the web ...

Difficult to help you not knowing what you want to do ....

Alain

aratti
- 23rd November 2009, 15:07
i think none understands my quetion.i want to run like this code ..
i want both programes to run apart from each other its just example so i can write my programe like this plz help


You can obtain the two leds flashing at a different interval with a couple of variable:




Dled Var Byte
Dled1 var Word

main: ' led will blink @ 0,1 sec; led1 will be on for 2 secs off for 0,2 sesc
Pause 1

Dled = Dled + 1
Dled1 = Dled1 + 1

If Dled =>100 then
Toggle led
Dled = 0
endif

If Dled1 = 1 then high led1
If Dled1 = 2000 low led1
If Dled1 =>2200 then Dled1 = 0


goto main



Al.

Mus.me
- 23rd November 2009, 18:56
this is wat i want to do but the serin cuz the 7seg leds blinkin and not working look at the quote #3 up u will see the schematic and the code to


@ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
DEFINE OSC 4


intcon = 0
vrcon = 0
CMCON = 7

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte

PORTA = %00001
PORTB = %11000000
TRISA = %00001
TRISB = %11000000

B0 = 0

loop:
''''' i tryed clock but it cuz problem to
''''if i put here anythings so 7seg doesnt works,,,just blinkin

MAIN:
serin porta.0,n2400,[],b0 this serin cuzin delays so the 7seg led blink and 'stops
if btN = 0 then b0 = b0 - 1
if btm = 0 then b0 = b0 +1
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTB.0[index] = 1
PAUSEUS 999
PORTB=0
NEXT INDEX

GOTO MAIN ' return not workling????

END
data @0,3,159,37,13,153,73,65,31,1,9[/QUOTE]

Acetronics2
- 23rd November 2009, 19:08
as Serin WAITS for the incoming data ...

difficult to have a precise timing !!!

HSERIN offers the USART Rx interrupt flag polling ( doesn't stop the program flow ...) AND BYTE "recording" ...

with a device showing an USART, of course... but the 628 has an inbuilt USART.

Soooo ... just use it !!!

Alain

Mus.me
- 24th November 2009, 02:30
WELL THIS IS MY CODE WHEN I CLICK SENT DATA (1234)FROM PC TO PIC16F628. I SEE IT FOR LESS THAN 1 SECOND THEN THE 7SEG GOES OFF TILL I CLICK AGAIN TO SEND I SEE IT JUST BLINK 1234. I DONNO HOW TO USE INTERRUPTS OR STOP HSERIN AND LET THE LOOP WORKING .PLZ HERE I WANT TO SAVE THE HSERIN DATA IN HR VAR AND STAY ON TILL I SENT OTHER DATA TO CHANGE .PLZ HELP ,THANK U...

@ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
DEFINE OSC 4
DEFINE HSER_RCSTA 90H
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
DEFINE HSER_EVEN 1
DEFINE HSER_ODD 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

PORTA = %00000
PORTB = %11000000
TRISA = %00000
TRISB = %11000000
intcon = 0
vrcon = 0
CMCON = 7

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte
MN VAR WORD
HR VAR word



MAIN:
HSERIN [DEC4 hr]

B0 = HR
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTA.0[index] = 1
PAUSEus 999
PORTA=0
NEXT INDEX

goto main

END
data @0,3,159,37,13,153,73,65,31,1,9

aratti
- 24th November 2009, 21:13
Try to make these two correction to your code:



MAIN:
HSERIN 10,Skip00, [DEC4 hr]

B0 = HR
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

Skip00:

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTA.0[index] = 1
PAUSEus 999
PORTA=0
NEXT INDEX

goto main



Al.

Mus.me
- 25th November 2009, 13:22
THANK YOU ARATTI,Acetronics FOR HELPING ME, I DID THIS IT WORKS GREAT NOW IM PULLING SOME HAIR TO WAKE THE PIC FROM SLEEP WHEN I SEND DATA BUT STILL NOT WORKING YET HERE S MY CODE
@ DEVICE WDT_OFF, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
DEFINE OSC 4
DEFINE HSER_RCSTA 90H
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
DEFINE HSER_EVEN 1
DEFINE HSER_ODD 1
'DEFINE HSER_TIMEOUT 1 ' Clear overflow automatically

PORTA = %00000
PORTB = %00000000
TRISA = %00000
TRISB = %00000000
intcon = 0
vrcon = 0
CMCON = 7

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte
MN VAR WORD
HR VAR word
j var byte

b0 = 0
loop:
j = j + 1
if j = 200 then SLP
HSERIN 10,main,[DEC4 b0]
MAIN:

D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]

for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTA.0[index] = 1
PAUSEus 999
PORTA=0
NEXT INDEX
goto loop
SLP:
CLEAR
RCREG = 1
RCSTA .7=1
RCSTA.4=1
RCSTA.5 = 1
RCSTA.6=1
TXSTA.7=0
TXSTA.4=1
PIE1.5 = 1
PORTB= %00000001

OPTION_REG = %00000001 'F628 can use 4>7 pins to wake up sleep
INTCON.1 = 0
INTCON.4 = 1
@ SLEEP
@ NOP
HIGH PORTB.6
PAUSE 100
LOW PORTB.6
CLEAR
RETURN
END
data @0,3,159,37,13,153,73,65,31,1,9

Acetronics2
- 25th November 2009, 13:57
Hi, Mus.me

Took me time to find the thread ...

have a look here ...

That is what you're looking for ...

http://www.picbasic.co.uk/forum/showpost.php?p=80228&postcount=2

best :
http://www.picbasic.co.uk/forum/showpost.php?p=18151&postcount=2


Alain

... and now, just use " Wake up on interrupt " ... as you have the interrupt flag !!!

Mus.me
- 25th November 2009, 14:12
i will have a look THANK YOU VERY MUCH Acetronics and aratti and my wishes for u

Mus.me
- 25th November 2009, 21:05
i did all these reading the datasheep 16f628a but still dont work

CLEAR
RCREG = 1
RCSTA .7=1
RCSTA.4=1
RCSTA.5 = 1
RCSTA.6=1
TXSTA.7=0
TXSTA.4=1
PIE1.5 = 1
PIR1.5=0
OPTION_REG = %00000001 'F628 can use 4>7 pins to wake up sleep
INTCON.1 = 0
@ SLEEP
@ NOP

Archangel
- 26th November 2009, 21:16
i think none understands my quetion.i want to run like this code ..
i want both programes to run apart from each other its just example so i can write my programe like this plz help



main: ' i wa]nt this led to blink forever without any other delay or stops
high led
pause 100
low led
pause 100
goto main

loop: ' and i want this led1 to blink without any other delay or stop
high led1
pause 2000
low led1
pause 200
goto loop
You might try this:


main:
For ledvar = 0 to 100
low led
pause 100
high led
pause 100

next ledvar

low led1
For ledvar = 0 to 100
low led
pause 100
high led
pause 100

High LED1
goto Main

Mus.me
- 27th November 2009, 01:06
the big problem i have now is to wake up pic 16f628 from sleep using usart interrupt hserin i tested PIR1 it occur but in sleep mode it doesnt occur . i donno i think im runing usart on synchronous slave mode thats what says the datasheet but i donno wheres my problem .my project is to transmet data to pic then wake it up . here is my code .

@ DEVICE WDT_ON, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"

DEFINE OSC 4
RCSTA=$90'DEFINE HSER_RCSTA 90H
TXSTA = $20'DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
'DEFINE HSER_EVEN 1
'DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER_TIMEOUT 1 ' Clear overflow automatically

PORTA = %00000
PORTB = %00000010
TRISA = %00000
TRISB = %00000010
intcon = 0
vrcon = 0
CMCON = 7
j var BYTE
led var portb.7

LOOP:
j = j + 1
if j = 255 then SLP
high led2
HSERIN 10,main,[DEC4 b0]

goto loop

' here will be my programe
SLP:
low led
RCSTA.4=0
pause 100
INTCON.6 = 1
RCSTA.4 = 1
PIE1.5 = 1
PIR1.5 = 0
@ SLEEP
@ NOP
PAUSE 1000
HIGH PORTB.6
PAUSE 1000
LOW PORTB.6
GOTO LOOP
END
please help i had read all the usart datasheet and i did what it says but nothings i think the problem in sync slave mode or the osc goes off during sleep or usart not reciving data even i did set it to recive data and interrupt..
and acetronics says (Alain

... and now, just use " Wake up on interrupt " ... as you have the interrupt flag !!! i donno where to put on interupt i trayed it many ways but nothings when it goes to sleep it die just like my nan bless her ..

aratti
- 27th November 2009, 07:42
Mus.me, the time you are using to go to sleep it seems to to be too short. You have 2.5 secs available than your micro enter into the sleep process. I would use a word (J VAR WORD) and set at least 20 seconds, otherwise you cannot even read the display.



LOOP:
j = j + 1
if j = 255 then SLP '2.5 secs is a too short time use a word
high led2
HSERIN 10,main,[DEC4 b0]

goto loop



Remove the two long pause in your code (after sleep command) otherwise when micro wakes has to process the two pauses and will loose the Tx data, and will return to sleep.



@ SLEEP
@ NOP
PAUSE 1000
HIGH PORTB.6
PAUSE 1000
LOW PORTB.6
GOTO LOOP



Al.

Mus.me
- 27th November 2009, 13:23
thank u aratti for reply i think the problem is in usart when pic goes in sleep mode the something aint working to receive data from PC TX , i tryed everythings 3days now but nothings .here where i have the problem, why it doesnt wake up the chip ?? lol

SLP:
OPTION_REG.7 = 0
RCSTA.4=0
pause 100
INTCON.6 = 1
RCSTA.4 = 1
PIE1.5 = 1
PIR1.5 = 0
@ SLEEP
@ NOP
GOTO LOOP
sorry for asking to much but i really wants to learn pbp very good im reading the whole datasheet every nights it helps and i get to much help and ideas from this forum thank u everyone

Gusse
- 27th November 2009, 15:15
Hi Mus.me,

I think you should turn on global interrupt enable (GIE) bit.

INTCON.7 = 1
Isn't that the master switch for all interrupts?

BR,
-Gusse-

Mus.me
- 27th November 2009, 15:30
Hi Mus.me,

I think you should turn on global interrupt enable (GIE) bit.

INTCON.7 = 1
Isn't that the master switch for all interrupts?

BR,
-Gusse-
hello Gusse thank u for help , i did that not working, i think i have problem in slave senchronous or somethings goes off when sleep mode .im sending 4 numbers from the pc and it works great .but in sleep mode it doesntwake it up

aratti
- 27th November 2009, 15:46
Mus.me, HSERIN is an asynchronous serial function. You cannot awake from sleep the mcu with HSERIN you should search another way. If you have PortB.0 available then you could use the interrupt on portB.0, for instance you could connect RTS pin to portB.0 (via a level translator) and before TX you pull high RTS to wakeup the pic.

Al.

Melanie
- 27th November 2009, 16:03
Actually on a 16F628, the USART can wake the PIC from sleep... I'd handle it outside of HSERIN though (you wouldn't be able to put the PIC into SLEEP initially from inside HERSIN anyway).

Acetronics2
- 27th November 2009, 16:05
Hi, Mus

I played a bit with the HSERIN Command ... but Wake up only works in Synchronous mode ( roughly consider USART is disabled when sleep mode ... as the system clock is ... down !)

sooo ...

last option is to use a comparator interrupt: tie the comparator input to RX Pin ( seems Porta is unused ...) and use the comparator interrupt for wake up ...

Alain

Mus.me
- 27th November 2009, 16:39
Thank you all for help and i will satill trying everythings to get it works.my project i want to buil is to control a cam and transmeter and some hardwares away from me and to shut them off and the pic to .so when i wake up the pic i send data to start the tranmeter and other hardware i will use the relays , i know how to do it but i need to save energy bcz the elctric goes off sometimes when its raining or windy thats why i want to put everythings shuted off and pic in deep sleep lol. THANK U ADAIN N MY WISHES

Mus.me
- 27th November 2009, 19:06
Hi again i did tried portb.0 with rx using led it works good , but if u tried by resistor or sometthing else it will wake up pic but no data receiving from usart .well thank u everyones for helping me.
Regards

SLP:
CLEAR
PORTB = %00000011
OPTION_REG = %00000001
INTCON.1 = 0
INTCON.4 = 1
@ SLEEP
@ NOP
B0 = 0
GOTO LOOP

Mus.me
- 27th November 2009, 20:17
this is my code example it works great, i put pic to sleep sinding 1919 and i wake up pic when i send any number ,using serial communicator in mcode studio.
'pic16f628a
@ DEVICE WDT_ON, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
Include "modedefs.bas"
PCON.3=1
DEFINE OSC 4
RCSTA=$90'DEFINE HSER_RCSTA 90H
TXSTA = $20'DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
'DEFINE HSER_EVEN 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER_TIMEOUT 1 ' Clear overflow automatically
define RX_INT PIR1,RCIF ;-- USART Receive Interrupt
PORTA = %00000
PORTB = %00000011
TRISA = %00000
TRISB = %00000011
intcon = 0
vrcon = 0
CMCON = 7

SDO Var PortB.4
SCLK Var PortB.5
BTM Var PortB.6
BTN VAR PORTB.7
SEG var byte
Digit var byte[4]
index var byte
B0 var word
D0 var byte
j var BYTE





b0 = 0
LOOP:
if B0 = 1919 then SLP
HSERIN 10,main,[DEC4 b0]
MAIN:
'im using here dsr 7segment leds with 74hc164 , bcz not found lcds in my country no pic ic
D0 = B0 DIG 0
READ D0,DIGIT[0]
D0 = B0 DIG 1
READ D0,DIGIT[1]
D0 = B0 DIG 2
READ D0,DIGIT[2]
D0 = B0 DIG 3
READ D0,DIGIT[3]
for index = 0 to 3
seg = digit [index]
SHIFTOUT SDO,SCLK,0,[SEG\8]
PORTA.0[index] = 1
PAUSEus 999
PORTA=0
NEXT INDEX
goto loop

SLP:
CLEAR
PORTB = %00000011 ,,, tried portb.0 with rx port ising led ot IR ld .
OPTION_REG = %00000001
pause 100
INTCON.1 = 0
INTCON.4 = 1
@ SLEEP
@ NOP
B0 = 0000
PAUSE 100
HIGH PORTB.7 ' just to see pic is wake up
PAUSE 1000
LOW PORTB.7
GOTO LOOP
END
data @0,3,159,37,13,153,73,65,31,1,9 'here s the numbers from 0 to 9


thanks a lots for helping

Mus.me
- 29th November 2009, 23:20
HELLO EVERYONES AGAIN LOL, IM TRYING TO SEND DEC NUMBERS FROM PC TO PIC BUT I DONNO HOW TO WHY WHEN I SEND EX: 15 IT STORES $60 IN EEPROM OR DEC 20 IT STOR $08 . AND IT STUCKS I SEND 5 TIMES OR MORE THEN IT RECEIVE THEM 1 TIME ....????????


@ DEVICE WDT_ON, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
INCLUDE "MODEDEFS.BAS"

intcon = 0
vrcon = 0
CMCON = 7



PORTB =%00000010
TRISB = %00000010


SO con 2
SI con 1
B0 var byte

mainloop:
Serin2 SI,N2400,[B0] ' GETTING DECIMAL NUMBERS FROM PC
'USING SERIAL COMMUNICATOR
If B0 Then print
GOTO MAINLOOP
print:

WRITE 5,B0 'SAVE NUMBERS IN EEPROM
PAUSE 100
Serout2 SO,N2400,[B0]
Goto mainloop

aratti
- 30th November 2009, 00:25
HELLO EVERYONES AGAIN LOL, IM TRYING TO SEND DEC NUMBERS FROM PC TO PIC BUT I DONNO HOW TO WHY WHEN I SEND EX: 15 IT STORES $60 IN EEPROM OR DEC 20 IT STOR $08 . AND IT STUCKS


Mus.me,
Serin2 SI,N2400,[B0] is wrong. For 2400 bauds use : Serin2 SI,396,[B0]. The same apply for SEROUT2.

Do you use hyperterminal for RS232 com with the pic?


...... I SEND 5 TIMES OR MORE THEN IT RECEIVE THEM 1 TIME ....????????

WRITE 5,B0 'SAVE NUMBERS IN EEPROM

You are writing "5 TIMES OR MORE" in the same location, so at the end you will see only the last byte Txed.

Al.

Mus.me
- 30th November 2009, 01:35
hello everyones again lol, im trying to send dec numbers from pc to pic but i donno how to why when i send ex: 15 it stores $60 in eeprom or dec 20 it stor $08 . And it stucks


mus.me,
serin2 si,n2400,[b0] is wrong. For 2400 bauds use : serin2 si,396,[b0]. The same apply for serout2.

Do you use hyperterminal for rs232 com with the pic?



write 5,b0 'save numbers in eeprom

you are writing "5 times or more" in the same location, so at the end you will see only the last byte txed.

Al.

thank you aratti im using serial communicator in microcode studio . But still gettin wiered symboles when i send from pic to the pc . I want to send dec and ascii but i donno how

aratti
- 30th November 2009, 08:34
...... But still gettin wiered symboles when i send from pic to the pc . I want to send dec and ascii but i donno how

Mus.me, all the ascii from 0 to 31 will give you wierd symboles, and 32 will show nothing because is space. This is the reason why you use the notation DEC before the variable to Tx.

If you want to receive both decimal and ascii you can Tx twice the variable

Serout2 SO,390,[DEC B0, " ", B0,13,10]

or you can select in which format to send out the variable depending on its value

IF B0<33 Then
Serout2 SO,390,[DEC B0,13,10]
ELSE
Serout2 SO,390,[B0,13,10]
ENDIF

Al.

Mus.me
- 30th November 2009, 22:16
mus.me, all the ascii from 0 to 31 will give you wierd symboles, and 32 will show nothing because is space. This is the reason why you use the notation dec before the variable to tx.

If you want to receive both decimal and ascii you can tx twice the variable

serout2 so,390,[dec b0, " ", b0,13,10]

or you can select in which format to send out the variable depending on its value

if b0<33 then
serout2 so,390,[dec b0,13,10]
else
serout2 so,390,[b0,13,10]
endif

al.
thank you very much aratti for ur help .i tryed it whith baud 16780 it works good i send from pc to pc and from pic to pc its the same i get using serial communicator of microcode studio .i will try with transmeter and receiver bcz i tryed it using ir it does error .got a amall robot to test likw remote control than i carry on have agreat day ARATTI ...

Mus.me
- 1st December 2009, 20:36
HI ARATTI,

I DID THIS CODE IT WORKS GREAT THNK U FOR HELP

SYNC CON "A"

SO con 1
SI con 0
B0 var WORD
B0 = 0
MAIN:
Serin2 SI,16780,10,MAIN,[WAIT(SYNC), DEC4 B0]

SerOUT2 SO,16780,["OK MUS ..! ",DEC4 B0]

GOTO MAIN

NOW IM TRYING INFRARED BUT STILL NOT WORKIN I KNOW IR RUNS ON 40KHZ, AND IVE GOT TRANSMITTER AND RECEIVER I FOUND THEM IN PROBASIC STATION METEO WAS SENDING FROM OUTSIDE TO THE CLOCK IN MY ROOM I TOOK THEM OFF BUT AINT WORKIN .
REGARDS