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?
Code:
'*****************************************************************
'* 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 =========================================================
Bookmarks