DEMO ANALOG NEEDLE METER
|
Device = 33EP128MC504 Declare Xtal = 150 Declare Watchdog = OFF Declare Warnings = Off Declare Stack_Expand = On Declare Optimiser_Level = 3 Declare Access_Upper_64K = On '================ TFT SCREEN ================ $define TFT_IC ILI9486 $define TFT_COM PAR_16b Symbol TftScreenWidth 480 Symbol TftScreenHeight 320 Symbol TftDataWord PORTB Symbol TFT_CS PORTC.9 Symbol TFT_WR PORTC.4 Symbol TFT_RESET PORTC.2 Symbol TFT_DC PORTC.1 Symbol TFT_RD PORTA.10 '================ TFT TOUCH ================ $define TOUCH_IC XPT2046 $define TOUCH_COM SPI_SW $define Z_Threshold 600 $define TouchAveragePoints 6 $define TouchMedianDistance 8 $define T_CS PORTC.8 $define T_IRQ PORTA.8 $define T_MOSI PORTA.4 $define T_MISO PORTA.9 $define T_SCLK PORTC.3 $define _T_MOSI _PORTA.4 $define _T_MISO _PORTA.9 $define _T_SCLK _PORTC.3 '================ MCU ================ $define McuType 1 '================ SD CARD ================ $define SDCardUsed 0 $define SDCardFatUsed 0 $define SD_COM SPI_1 $define SD_CS PORTA.1 $define SD_SDO PORTA.4 $define SD_SDI PORTA.9 $define SD_CLK PORTC.3 $define _SD_SDO _PORTA.4 $define _SD_SDI _PORTA.9 $define _SD_CLK _PORTC.3 '================ MEMORY ================ $define MemoryType 0 $define MEM_COM SPI_1 $define MEM_CS PORTA.7 $define MEM_MOSI PORTA.4 $define MEM_MISO PORTA.9 $define MEM_SCLK PORTC.3 $define _MEM_MOSI _PORTA.4 $define _MEM_MISO _PORTA.9 $define _MEM_SCLK _PORTC.3 $define MEM_PAGE_SIZE 256 $define MEM_SECTOR_SIZE 4096 $define MEM_SECTOR_COUNT 2048 $define MEM_FILE_COUNT 256 $define MEM_WRITE_DELAY 5 '================ FONT ================ $define FontSmooth 1 $define FontMaxPixels 16 $define FontMaxSpace 16 Include "TftLib\Fonts\SND\F0_SND_8x8_Basic.inc" Include "TftLib\Fonts\SND\F4_SND_16x16_Regular.inc" Include "TftLib\Fonts\BDF\F2_BDF_Margarine-Regular-24.inc" Include "TftLib\TFT_Graphic_Lib.inc" Dim bCounter1 As Byte Dim wTemp As Word Dim fVoltage As Float Dim fCurrent As Float Dim fVoltageNeedle As Float Dim wCurrentSlideX As Word Dim fCurrentScale As Float Main: Clear SetCrystal() SetPins() TftSetUp(0) SetScreen()
fCurrentScale = 2 / 175 wCurrentSlideX = 260 fVoltageNeedle = 1
'Seed random value Seed $0123
While 1 = 1 fCurrent = (Random / 32768) fVoltage = (Random / 655) PrintCurrent() PrintVoltage() DelayMS 250 Wend End Proc PrintCurrent() TftRectangleTCG(260,57, 304,73, WHITE,GREEN, 0) TftRectangleTCG(305,57, 349,73, GREEN,YELLOW, 0) TftRectangleTCG(350,57, 435,73, YELLOW,RED, 0) TftRectangleSNCP(wCurrentSlideX,54, 4, 4, GLAUCOUS) TftRectangleSNCP(wCurrentSlideX,76, 4, 4, GLAUCOUS)
wCurrentSlideX = 260 + fRound(fCurrent / fCurrentScale) TftRectangleSNCP(wCurrentSlideX,54, 4, 4, BLACK) TftRectangleSNCP(wCurrentSlideX,76, 4, 4, BLACK) TftLineVN(wCurrentSlideX,54,76,BLACK) TftPrintSndDecimal(fCurrent, 1, 2, 2, 284, 16, 0, BLACK, LIBERTY, 0) EndProc Proc PrintVoltage() TftArcRL(60,230, 420,230, 400,0, SKY_BLUE, -33, -100, fVoltageNeedle) fVoltageNeedle = 1 - fVoltage / 100 TftArcRL(60,230, 420,230, 400,0, BLACK, -33, -100, fVoltageNeedle) fVoltage = fVoltage / 23.81 TftPrintSndDecimal(fVoltage, 1, 2, 3, 37, 27, 0, BLACK, SKY_BLUE, 0) EndProc Proc SetScreen() TftResetScreen(BLACK) TftSetSndFont(2,1) TftPrintSndString("Booting ... Please wait!", 1, 55, 130, 0, WHITE, BLACK, 0) DelayMS 2000 'Display off TftDisplayOff()
'Reset screen TftRectangleTCG(0,0, 479,319, CREAM,CITRINE, 1)
'Outside frame TftRectangleETTCI(0,0, 479,319,ONYX, 5) TftRectangleRC(0,0, 479,319, 20, 0,ONYX, 5,-1)
'Scale window TftRectangleRC(30,100, 450,310, 30, 1,SKY_BLUE, 0,0) TftRectangleRC(30,100, 450,310, 30, 0,GLAUCOUS, 5,-1)
'5 zone scale For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, RED, 0, 0.2, -bCounter1) Next For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, ORANGE, 0.2, 0.4, -bCounter1) Next For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, YELLOW, 0.4, 0.6, -bCounter1) Next For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, GREEN, 0.6, 0.8, -bCounter1) Next For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, WHITE, 0.8, 1, -bCounter1) Next
'Scale frame TftArcRLThickness(1) TftArcS(60,230, 420,230, 400,0, BLACK, 0, 1, 0) TftArcS(60,230, 420,230, 400,0, BLACK, 0, 1, -30) TftArcRL(60,230, 420,230, 400,0, BLACK, 0, -30, 0) TftArcRL(60,230, 420,230, 400,0, BLACK, 0, -30, 1)
'Scale major dividers For bCounter1 = 1 To 4 wTemp = bCounter1 * 2 TftArcRL(60,230, 420,230, 400,0, BLACK, -5, -30, wTemp / 10) Next
'Minor dividers For bCounter1 = 1 To 24 wTemp = bCounter1 * 4 TftArcRL(60,230, 420,230, 400,0, BLACK, -15, -30, wTemp / 100) Next
'Labels TftSetBdfFont(2) TftPrintBdfString("MIN", 48, 250, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("20%", 110, 270, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("40%", 186, 280, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("60%", 264, 280, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("80%", 340, 270, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("MAX", 390, 250, 480, 0, WARM_BLACK, WHITE, 1)
'Needle set TftArcRLThickness(3) 'Needle window For bCounter1 = 0 To 30 TftArcS(60,230, 420,230, 400,0, ISABELLINE, 0, 1, -103 - bCounter1) Next TftRectangleTCG(106,106, 374,138, ICEBERG, ISABELLINE, 1) TftRectangleSNTC(160,138, 314,150, ISABELLINE) TftSetSndFont(0,1) TftPrintSndString("Battery Voltage 4.2v", 1, 160, 126, 0, BLACK, WHITE, 1)
'Readings window TftRectangleRC(30,10, 235,94, 10, 1,SKY_BLUE, 0,0) TftRectangleRC(30,10, 235,94, 10, 0,GLAUCOUS, 5,-1)
TftSetSndFont(4,1) TftPrintSndDecimal(fVoltage, 1, 2, 3, 37, 27, 0, BLACK, SKY_BLUE, 0)
'Current readings TftRectangleRC(245,10, 450,94, 10, 1,LIBERTY, 0,0) TftRectangleRC(245,10, 450,94, 10, 0,GLAUCOUS, 5,-1) TftSetSndFont(0,1) TftPrintSndString("Battery Current 2A", 1, 276, 80, 0, BLACK, WHITE, 1) TftRectangleETTCO(260,57, 435,73, GLAUCOUS,5) TftRectangleTCG(260,57, 304,73, WHITE,GREEN, 0) TftRectangleTCG(305,57, 349,73, GREEN,YELLOW, 0) TftRectangleTCG(350,57, 435,73, YELLOW,RED, 0) TftSetSndFont(4,1) TftPrintSndDecimal(fCurrent, 1, 2, 2, 284, 16, 0, BLACK, LIBERTY, 0)
'Display on TftDisplayOn() EndProc 'Set Fosc Proc SetCrystal() 'Crystal = 16 MHz --> PLLDIV = 68 for 140MHz / PLLDIV = 73 For 150MHz CLKDIV = %0000000000000010 'PLLPRE = 2 ; PLLPOST = 0 PLLFBD.Byte0 = 73 '--> 150MHz Fp 'Wait for oscillator PLL lock While OSCCON.5 = 0 : Wend DelayMS 100 EndProc Proc SetPins() 'Set all digital ANSELA = 0 ANSELB = 0 ANSELC = 0
SPI1CON1 = 0x033B '8b / SPRE[2:0] 2:1 / PPRE[1:0] 1:1 SPI1STAT = 0x8000 EndProc Config FICD = ICS_PGD1, JTAGEN_OFF Config FPOR = ALTI2C1_OFF, ALTI2C2_OFF, WDTWIN_WIN25 Config FWDT = FWDTEN_OFF, PLLKEN_ON, WDTPOST_PS16384, WDTPRE_PR128, WINDIS_OFF Config FOSC = FCKSM_CSECMD, IOL1WAY_OFF, OSCIOFNC_OFF, POSCMD_HS Config FOSCSEL = FNOSC_PRIPLL, IESO_ON, PWMLOCK_OFF Config FGS = GCP_OFF, GWRP_OFF |
Created with the Personal Edition of HelpNDoc: Transform your help documentation into a stunning website