'*************************************************************************
' Test example for 4 digits with 15 segments using VK16K33 chip
' Pic18F46k22, OshonSoft Pic18 Basic Compiler v6.10
' Using the MSSP module in I2C mode and FrameBuffer.
' By COS, doglfu66@yahoo.es
' v2026/07/16
'*************************************************************************
' ************************************************************************
' ************************************************************************
' PCB HL-K18 Jumper Configuration:
' General Jumpers on HL-K18: VCC, GND, PGC, PGD, OSC2, OSC1, VPP
' RS232 Interface: TX (Transmit), RX (Receive), BZ (Buzzer)
' Specific Jumpers for this setup: NONE
' Switches S2 and S4 should both be set to OFF.
' PICKIT2 Jumpers on HL-K18: Not used, external programmer.
' ************************************************************************
' Configuration of microcontroller fuses
' Setting up internal oscillator with 4x PLL to achieve 64MHz system clock
' MCLR enabled for external reset <---------------------------------------
#define CONFIG1L = 0x00  ' Low Power Timer and memory settings
#define CONFIG1H = 0xF8  ' External oscillator with PLL enabled
#define CONFIG2L = 0x1E  ' Brown-out Reset, Power-Up Timer
#define CONFIG2H = 0x3C  ' Watchdog Timer setup
#define CONFIG3L = 0x00  ' Low-voltage programming disabled
#define CONFIG3H = 0xBD  ' Port configuration options
#define CONFIG4L = 0x80  ' Stack overflow and underflow reset enabled
#define CONFIG4H = 0x00  ' Additional configuration bits
#define CONFIG5L = 0x0F  ' Code protection
#define CONFIG5H = 0xC0  ' Data EEPROM code protection
#define CONFIG6L = 0x0F  ' Write protection settings
#define CONFIG6H = 0xE0  ' Configuration protection bits
#define CONFIG7L = 0x0F  ' Boot block protection settings
#define CONFIG7H = 0x40  ' Configuration for block protection
' General configuration
#define CLOCK_FREQUENCY = 64		' System clock frequency in MHz
#define SINGLE_DECIMAL_PLACES = 1	' Number of decimal places for floating-point operations
#define STRING_MAX_LENGTH = 40		' Maximum length for String variables
'#define SIMULATION_WAITMS_VALUE = 0 'Activate only in simulation.
'*************************************************
'*************************************************
Include "_Pic18F46K22Lib.bas"
'Include "CLib.bas"
Include "_I2CLib.bas"
Include "VK16K33_I2C.bas"
'*************************************************
Main:
	'Clock internal 64Mhz.
	Call _Setup_Oscillator(_OSC_16MHz_HF)
	Call _SET_PLL4(_PLL_ON)
	Call _Interrupts_Mode(_DISABLE_PRIORITY)
	Call _SlewRate(_Disable) 'Enabled by default.
	'*********************************************
	AllDigital
	UART1_Init 115200
	'UART2_Init 4800
	WaitMs 1
	'*********************************************
	UART1_Write 0x0C
	WaitMs 100
	UART1_Write "Ready", CrLf
	WaitMs 100

	Init_I2C(400, 64) ' Initialize MSSP1 module in I2C master mode at 400KHz
    WaitMs 10

	VK16K33_Init()
	VK16K33_Display_On()
	'VK16K33_Set_Blink(2)
	VK16K33_Set_Brightness(1)
	'VK16K33_DPMode(False) ' True by defauld


	Dim i As Byte
	Dim cont As Integer
	cont = -100
	Dim float As Single
	float = -5.3
	Dim str[25] As String


	VK16K33_Test()
	WaitMs 2000


	VK16K33_Clear()
	CFor (i = 0; i < VK16K33_Digits; ++i)
		VK16K33_Cursor(i)
		VK16K33_PutC(#i)
		VK16K33_Update()
		WaitMs 500
	CNext
	VK16K33_Set_Blink(1)
	WaitMs 2000
	VK16K33_Set_Blink(0)
	WaitMs 1000


	VK16K33_Clear()
	'VK16K33_DPMode(True)
	VK16K33_Cursor(0)
	VK16K33_Print(#float + "C")
	VK16K33_Update()
	WaitMs 2000


	VK16K33_Clear()
	VK16K33_Cursor(0)
	VK16K33_PutC("*")
	VK16K33_Cursor(3)
	VK16K33_PutC("*")
	VK16K33_Update
	WaitMs 2000


	VK16K33_Clear()
	float = -100
	While cont <= 100
		VK16K33_Cursor(0)
		VK16K33_PadLeft(" ", str = #cont)
		VK16K33_Print(str)
		VK16K33_Update()
		++cont
		WaitMs 50
	Wend
	WaitMs 2000

	float = -12
	str = " TEMPERATURE "
	VK16K33_ScrollReset()
	'VK16K33_DPMode(True)
	While True
		VK16K33_ScrollLeft(str + #float + "C")
		float = float + 0.1
		WaitMs 400
	Wend


End









