PDA

View Full Version : Strong processing routine



MegaADY
- 20th June 2004, 15:29
Hello ! I have a simple question . Let's say I have in the internal EEPROM of 16f628A the following sequence:
EA F4 D3 F5 B9. How do I serout2 the following sequence : A 4 3 5 9 .
The ideea is whatever i have in a location A2 B1 C1 D1 E1 or F1 , I have to output 1 (the second digit).
Please help me

TONIGALEA
- 20th June 2004, 16:43
you can use the Hex modifier , using hex1 gives you just the secong digit that you need you as below
hex1 variable ==> this displays only the secong digit
so if your hex value of $EA was in variable called Data_Out
HEX1 Data_Out would only display A
heres a quick example


DEFINE LOADER_USED 1 ' uses a bootloader

'@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
INCLUDE "Modedefs.Bas"
Define OSC 20
clear


' Setup Hardware for uart
DEFINE HSER_BAUD 19200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1



DEFINE LCD_DREG PORTD ' Use Portd for LCD Data
DEFINE LCD_DBIT 4 ' Use Upper(4) 4 bits of Port
' PORTD-4 thru PORTD-7 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTE ' PORTE for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 0 ' PORTE-0 pin for LCD's RS line
DEFINE LCD_EREG PORTE ' PORTE for Enable (E) bit
DEFINE LCD_EBIT 1 ' PORTE-1 pin for LCD's E line

DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 2000' Command Delay (uS)
DEFINE LCD_DATAUS 50 ' Data Delay (uS)

' ** Define LCD Control Constants **

I CON 254 ' Control Byte
Clr CON 1 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1
Line2 CON 192 ' Point to beginning of line 2



' Hardware Defines
' ----------------

SCL VAR PORTC.3 ' I2C clock pin
SDA VAR PORTC.4 ' I2C data pin


'
' Software Defines
' ----------------
' ** Declare the Variables **
Temp VAR WORD ' General Purpose
Data_Out VAR byte ' Data read from the Eeprom
Data_In VAR byte[5] ' Data written to the Eeprom
address VAR WORD ' Address

'
' Initialise Hardware
' -------------------
ADCON1=7
TRISA=%00000000
TRISB=%00000000
TRISC=%10000000
TRISD=%00000000


Pause 1000
LCDOut I,Clr:Pause 30
LCDOut I,Line1+2," 24C128 TEST "
LCDOut I,Line2+2,"..Power On.. !!"
Pause 1000 ' Allow Time for user to view
Data_Out=0:
Data_In[0]=$EA
Data_In[1]=$F4
Data_In[2]=$D3
Data_In[3]=$F5
Data_In[4]=$B9

'WRITE SUB
'=======
For address = 0 TO 4 ' Loop 16 times

I2CWrite SDA,SCL,%10100000,address, [Data_In[address ]] ' Write each 2 location

Pause 10 ' Delay 10ms after each write

Next address



loop:
'READ SUB
'=======
HSerout [" send : "]
For address = 0 TO 4 ' Loop 16 times
LCDOut I,Clr:Pause 30
I2CRead SDA,SCL,%10100000,address,[Data_Out] ' Read 2 locations in a row

LCDOut I,Line1+2," Eprom Values :"
LCDOut I,Line2+2,#address,": ",hex1 Data_Out ' Display Eprom Data
HSerout [HEX1 Data_Out]
Pause 1000
Next address
HSerout [10,13]

GoTo loop

End

This should display the following to hyperterminal
send : A4359
send : A4359


Hope this helps

Toni

MegaADY
- 20th June 2004, 16:48
Thank you very much !!!
It works !
Please tell me , where did you read abouut the HEX1 statement ?
I have the PicBasic documentation, but .. I couldn't find this .
Where can I get a more complex documentation ?
Thank you once again.
Best regards !

TONIGALEA
- 20th June 2004, 16:48
i was in a rush so correction to the following comments

For address = 0 TO 4 ' Loop 5 times

I2CWrite SDA,SCL,%10100000,address, [Data_In[address ]]
I2CRead SDA,SCL,%10100000,address,[Data_Out]


Toni

TONIGALEA
- 20th June 2004, 16:50
its in the manaul somewhere not quite sure where but i would go and dig it up

Toni

TONIGALEA
- 20th June 2004, 17:30
page 139-140 should give an idea

MegaADY
- 20th June 2004, 17:56
Excuse me for troubling you ....
The problem is not really solved . I'll tell you exactly what's all about :
This is my SMS routine :

buffer var byte[160]

send_sms:
Serout2 pinout,32, ["ATZ",13]: pause 1000
Serout2 pinout,32, ["AT+CMGF=1",13]:pause 1000
Serout2 pinout,32,["AT+CMGS=",34,"+40723302694",34,13]:pause 1500
Serout2 pinout,32,["test",26,13] 'text to send by sms
return

I have to send a SMS message via GSM .
Buffer is full of bytes: EA,FD,12,8A etc.
So, instead of "test" message, I have to take all 160 bytes from buffer and send only the second digit. My SMS should look like this: AD28
Excuse me once again for troubling you with theese little problems, but I am quite new into this. I have some applications so far, but ... as I told you I am at the begining,
Thank you !

TONIGALEA
- 23rd June 2004, 00:19
Try this and lets see how it goes
there are better ways of doing this but i am quite in a rush
Toni


' Hardware Defines
' ----------------

SCL VAR PORTC.3 ' I2C clock pin
SDA VAR PORTC.4 ' I2C data pin


'
' Software Defines
' ----------------
' ** Declare the Variables **
Temp VAR WORD ' General Purpose
Data_Out VAR byte ' Data read from the Eeprom
Data_In VAR byte[4] ' Data written to the Eeprom
address VAR WORD ' Address

'
' Initialise Hardware
' -------------------
ADCON1=7
TRISA=%00000000
TRISB=%00000000
TRISC=%10000000
TRISD=%00000000


Pause 1000
LCDOut I,Clr:Pause 30
LCDOut I,Line1+2," 24C128 TEST "
LCDOut I,Line2+2,"..Power On.. !!"
Pause 1000 ' Allow Time for user to view
Data_Out=0:
Data_In[0]=$EA
Data_In[1]=$FD
Data_In[2]=$12
Data_In[3]=$8A


'WRITE SUB
'=======
For address = 0 TO 3 ' Loop 16 times

I2CWrite SDA,SCL,%10100000,address, [Data_In[address ]] ' Write each 2 location

Pause 10 ' Delay 10ms after each write

Next address



loop:
'READ SUB
'=======
HSerout [" send : "]
For address = 0 TO 3 ' Loop 16 times
LCDOut I,Clr:Pause 30
I2CRead SDA,SCL,%10100000,address,[Data_Out] ' Read 2 locations in a row

LCDOut I,Line1+2," Eprom Values :"
if address < 3 then
LCDOut I,Line2+2,#address,": ",hex1 Data_Out ' Display Eprom Data
HSerout [HEX1 Data_Out]
else
Data_Out=Data_Out >>4

LCDOut I,Line2+2,#address,": ",hex Data_Out ' Display Eprom Data
HSerout [HEX Data_Out]
endif
Pause 1000
Next address
HSerout [10,13]

GoTo loop

End

TONIGALEA
- 23rd June 2004, 00:39
loop:
'READ SUB
'=======
HSerout [" send : "]
For address = 0 TO 3
I2CRead SDA,SCL,%10100000,address,[Data_Out]
if address < 3 then
Data_Send[address]=Data_Out
else
Data_Out=Data_Out >>4
Data_Send[address]=Data_Out
endif
Next address 'sends : AD28
HSerout [HEX1 Data_Send[0],HEX1 Data_Send[1],HEX1 Data_Send[2],HEX Data_Send[3]]
HSerout [10,13]
Pause 1000

GoTo loop

End
Or you could do something like this ..
i am not using the manual at the moment but there are better ways of doing this

MegaADY
- 23rd June 2004, 21:35
I already solved the problem , other way.
Thank you very much for your support !
Have a nice day !