PDA

View Full Version : SHIFTOUT with PIC12F675?



zorgloub
- 20th July 2023, 14:32
Hello to the Community.
Is the Shiftout command possible for a PIC12F675?
I ride a program using this command but my logic analyzer does not show me any pulse of Data and Clock!
Thanks.

zorgloub
- 20th July 2023, 16:22
Here is the test program...




'************************************************* ***********************
' Programme: Shiftout Test PBP (c)Roger LEGAT 07-2023
' RX Tester---> PIC 12F675
' PicBasicPro Compiler V:2.40 ---> 393 Words used
'************************************************* ***********************
'*** PIC Pinouts/Specifications
'------------------------------------
' PIC 12F675
' __ __
' Vcc +| U |- Gnd
' GPIO.5 x| |< GPIO.0
' GPIO.4 >| |> GPIO.1 _DIO
' GPIO.3 >| |> GPIO.2 _CLK
' -----

@ Device Pic12F675, intrc_osc, wdt_off, pwrt_on, mclr_off, protect_off

DEFINE OSC 4 ' Pulsin/Pulsout Resolution =10µsec => 1ms=100
' (Pulse Value of 1msec x10 =1000) [x10]
' Pause =1msec => 1msec=1 1sec=1000

Include "modedefs.bas" ;for shiftout command

CMCON = 7 'Comparator Off
ANSEL = 0 'Set Port to Digital i/o
ADCON0 = 0 'All ADC Off

Asm
bsf STATUS ;Bank 1
call 3FFh ;Get the CAL value from 3FF addresse YOU WRITE BEFORE !
movwf OSCCAL ;Calibrate
bcf STATUS, RP0 ;Bank 0
Endasm

'*** In/Out pins ..................................................
Output 1 : _DIO var GPIO.1
Output 2 : _CLK var GPIO.2

'*** Variables/Constants
Pack VAR BYTE ;Byte to send

'=== MAIN PROGRAM ================================================== ===

Pack = 255

MainLoop:

Shiftout _DIO,_CLK,LSBFIRST,[Pack\8] 'Send Byte
pause 100

Goto MainLoop


;=========== END OF PBP =================================================

Ioannis
- 22nd July 2023, 08:41
Maybe it is better to define the output register more convenitional.

Try

TRISIO = 0

DIO VAR GPIO.1
CLK VAR GPIO.2

and report back how is doing.

Ioannis

zorgloub
- 24th July 2023, 15:08
Hi,

I'm trying to understand and learn:

What might be the consequences if I set my ports as follows:

Dio var GPIO.0
or
Symbol Dio = GPIO.0

Does this make a difference to the way the program is processed?

Thanks

Ioannis
- 24th July 2023, 21:30
Originally the problem I think was this syntax:

'*** In/Out pins ..................................................
Output 1 : _DIO var GPIO.1
Output 2 : _CLK var GPIO.2

I do not see how this can compile.

Ioannis

zorgloub
- 25th July 2023, 08:58
Hello,
And yet the compiler didn't give any errors!?

I'm going to keep your suggested syntax anyway.

Concerning my problem with the Shiftout command, I note that a problem existed with this command for the Picaxe 08M2 (which is in fact a PIC12F1840).
The Shiftout command was not possible for this Picaxe and it was necessary to create a small routine explained in the Picaxe manual.

Before continuing my tests, I wondered if such a problem could also be encountered with my Pic12F675... ?

Ioannis
- 25th July 2023, 11:30
In PBP I never encountered any problems with SHIFTout or SHIFTin commands.

I pressume you will not have too.

Ioannis

Ioannis
- 25th July 2023, 14:20
Hello,
And yet the compiler didn't give any errors!?


Why would give any error?

output 1 or output 2 are valid commands that make pin 1 or pin2 output.

And then you define the aliases _DIO var GPIO.1 etc.

But did not defined the TRIS register.

Ioannis

zorgloub
- 31st July 2023, 12:56
Why would give any error?

But did not defined the TRIS register.

Ioannis

Isn't using the input or output commands for the ports used is not enough or does it work?

Ioannis
- 31st July 2023, 14:46
Yes but you defined wrong. For example _DIO var GPIO.1 is not the same as DIO var GPIO.1

Ioannis

zorgloub
- 1st August 2023, 15:57
Ah?
This unnderscore character has an influence for PBP?
I usually used this character to identify my entries or outputs on the MCU!

zorgloub
- 1st August 2023, 17:12
To come back to my original question about the SHIFTOUT command, here's the program I'm trying to run.
Unfortunately, I've noticed that the SHIFTOUT command doesn't produce any signals on the SDA and SCK output ports!
Any idea why?



'************************************************* ****************
'* Name : Pulsin to TM1637.PBP *
'* Author : RGL *
'* Date : 01/08/2023 *
'* Version : 1.0 *
'* Compiler : PBPro 2.6 *
'* Notes : 415 words used *
'* *
'* *
'************************************************* ****************


'*** PIC Pinouts/Specifications
'------------------------------------
' PIC 12F675
' __ __
' Vcc +| U |- Gnd
' GPio.5 | | GPio.0
' Pulse GPio.4 >| |> GPio.1 SDA (Data)
' GPio.3 | |> GPio.2 SCK (Clock)
' -----

@ Device Pic12F675, intrc_osc, wdt_off, pwrt_on, mclr_off, protect_off

'DEFINE OSC 4 ' Pulsin/Pulsout Resolution =10µsec => 1ms=100 DEFAULT VALUE
' (Pulse Value of 1msec x10 =1000) [x10]
' Pause =1msec => 1msec=1 1sec=1000

Include "modedefs.bas"

CMCON = 7 'Comparator Off
ANSEL = 0 'Set Port to Digital i/o
ADCON0 = 0 'All ADC Off

'OSCCAL = $4C (344C placed manually in the hex file at 3FF address)

Asm
;bsf STATUS ;Bank 1
call 3FFh ;Get the CAL value from 3FF addresse YOU WRITE BEFORE !
movwf OSCCAL ;Calibrate
;bcf STATUS, RP0 ;Bank 0
Endasm

'*** In/Out pins ..................................................

TRISIO = %010000 'GPIO.4 Input=1. All other Output=0

SDA Var GPIO.0 'Serial Data pin
SCK Var GPIO.1 'Serial Clock pin
Pulse Var GPIO.4 'Pulsin pin


'*** Variables/Constants

CHR1 VAR BYTE ;4 Byte to send
CHR2 var Byte
CHR3 var Byte
CHR4 var Byte

Value VAR WORD ;Average Pulsin Value to display
Measure VAR word ;Intermediate and successives readings

i VAR BYTE ;Working variable (20 successive measurements)


' TM1637 Commands
'-------------------
;CMD1 CON $40 'CMD1=$40 Write command Auto-increment Mode (Default Mode)
CMD2 CON $C0 'CMD2=$C0 Start 1st digit position(left most = 1st digit)
CMD3 CON $8C 'CMD3=$8A is the end command that turns the display ON and sets brightness to 69%


; Definition of the 10 characters in the EEPROM : 0-9 +Blank
; (Eeprom Starting address at 0)

; EEPROM(0 1 2 3 4 5 6 7 8 9 10 ) Pos10 = Blank
DATA @0,$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$00 ; Write to Eeprom

'=== INIT TM1637 ================================================== ===

Gosub StartSeq
SHIFTOUT SDA, SCK, 0, [CMD3] 'SHIFTOUT brightness
Gosub AckSeq
gosub StopSeq

'=== MAIN PROGRAM ================================================== ===
MainLoop:
Value = 0 : Measure = 0 'Initialize Value and Measure

For i=1 to 20 '20 successive measurements for stabilisation of the display
Pulsin Pulse,1,Measure
Value = Value + Measure
Next

Value = Value /20 ;Average PULSIN value
Value = Value * 10 ;Conversion to uS @4Mhz

; Decomposition Method:
; ------------------------
CHR1 = Value / 1000
If CHR1 = 0 then
CHR1 = 10 'Blank Char.
Else
CHR1 = CHR1+$80 '+Decimal point
Endif

CHR2 = Value / 100 // 10
CHR3 = Value / 10 // 10
CHR4 = Value // 10


'This sequence outputs now all 4 characters to the Display

Gosub StartSeq 'SHIFTOUT Mode 0 - LSB First, Clock normally low
SHIFTOUT SDA, SCK, 0, [CMD2] '1st Digit Adrress
Gosub AckSeq


SHIFTOUT SDA, SCK, 0, [CHR1] '1st Digit value
Gosub AckSeq

SHIFTOUT SDA, SCK, 0, [CHR2] '2e Digit value
Gosub AckSeq

SHIFTOUT SDA, SCK, 0, [CHR3] '3e Digit value
Gosub AckSeq

SHIFTOUT SDA, SCK, 0, [CHR4] '4e Digit value
Gosub AckSeq

Gosub StopSeq

Goto MainLoop

'================================================= ===================
'============= SUBROUTINES ====================================
'================================================= ===================

StartSeq:
High SCK
High SDA
Low SDA
Return
;--------------------------

ACKSeq:
Low SCK
High SCK
Low SCK
Return
;--------------------------

StopSeq:
Low SCK
Low SDA
High SCK
High SDA
Return

'=============== END OF PBP PROGRAMME ================================================== =======