    /**********************************************
* 7MHz AM TX VFO V1.0
* PIC24FV32KA302 family 
* 2026.4.23     
*
* 284x76 EstarDyn 2.259inch TFT LCD display program 
* LCD driver ST7785 SPI
*
* SI5351A 7.000-7.200 100kHz step VFO program
* Max 100V 電源電圧表示
  
     * 
 
***********************************************/
// PIC24FV32KA302 Configuration Bit Settings

// 'C' source line config statements

// FBS
#pragma config BWRP = OFF               // Boot Segment Write Protect (Disabled)
#pragma config BSS = OFF                // Boot segment Protect (No boot program flash segment)

// FGS
#pragma config GWRP = OFF               // General Segment Write Protect (General segment may be written)
#pragma config GSS0 = OFF               // General Segment Code Protect (No Protection)

// FOSCSEL
#pragma config FNOSC = FRCPLL           // Oscillator Select (8MHz FRC oscillator With Postscaler (FRCDIV))
#pragma config SOSCSRC = DIG            // SOSC Source Type 
#pragma config LPRCSEL = HP             // LPRC Oscillator Power and Accuracy (High Power, High Accuracy Mode)
#pragma config IESO = OFF                // Internal External Switch Over bit (Internal External Switchover mode enabled (Two-speed Start-up enabled))

// FOSC
#pragma config POSCMOD = NONE           // Primary Oscillator Configuration bits (Primary oscillator disabled)
#pragma config OSCIOFNC = ON            // CLKO Enable Configuration bit (CLKO output signal is active on the OSCO pin)
#pragma config POSCFREQ = HS            // Primary Oscillator Frequency Range Configuration bits (Primary oscillator/external clock input frequency greater than 8MHz)
#pragma config SOSCSEL = SOSCHP         // SOSC Power Selection Configuration bits (Secondary Oscillator configured for high-power operation)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Both Clock Switching and Fail-safe Clock Monitor are disabled)

// FWDT
#pragma config WDTPS = PS32768          // Watchdog Timer Postscale Select bits (1:32768)
#pragma config FWPSA = PR128            // WDT Prescaler bit (WDT prescaler ratio of 1:128)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable bits (WDT enabled in hardware)
#pragma config WINDIS = OFF             // Windowed Watchdog Timer Disable bit (Standard WDT selected(windowed WDT disabled))

// FPOR
#pragma config BOREN = BOR3             // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware, SBOREN bit disabled)
#pragma config LVRCFG = OFF             // Low Voltage Regulator Configuration bit (Low Voltage regulator is not available)
#pragma config PWRTEN = ON              // Power-up Timer Enable bit (PWRT enabled)
#pragma config I2C1SEL = PRI            // Alternate I2C1 Pin Mapping bit (Use Default SCL1/SDA1 Pins For I2C1)
#pragma config BORV = V20               // Brown-out Reset Voltage bits (Brown-out Reset set to lowest voltage (2.0V))
#pragma config MCLRE = ON               // MCLR Pin Enable bit (RA5 input pin disabled,MCLR pin enabled)

// FICD
#pragma config ICS = PGx1               // ICD Pin Placement Select bits (EMUC/EMUD share PGC1/PGD1)

// FDS
#pragma config DSWDTPS = DSWDTPSF       // Deep Sleep Watchdog Timer Postscale Select bits (1:2,147,483,648 (25.7 Days))
#pragma config DSWDTOSC = LPRC          // DSWDT Reference Clock Select bit (DSWDT uses Low Power RC Oscillator (LPRC))
#pragma config DSBOREN = ON             // Deep Sleep Zero-Power BOR Enable bit (Deep Sleep BOR enabled in Deep Sleep)
#pragma config DSWDTEN = ON             // Deep Sleep Watchdog Timer Enable bit (DSWDT enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.


#include <xc.h>
#include <string.h>


#define FCY 16000000UL// libpic30.hの前にFosc/2を定義　__delay関数用
#include <libpic30.h> 
#include "Font5G.h"
#include "Font9.h"
#include "Font22.h"

#define SI5351_I2C_ADDR     0xc0

#define SI5351_XTAL_FREQ    24998997
#define SI5351_PLL_FREQ     900000000

#define SI5351_OUTPUT_CTRL  3
#define SI5351_CLK0_CTRL    16
#define SI5351_CLK1_CTRL    17
#define SI5351_CLK2_CTRL    18
#define SI5351_PLL_A        26 //LO1
#define SI5351_PLL_B        34 //LO2
#define SI5351_MS_0         42
#define SI5351_MS_1         50
#define SI5351_MS_2         58  //	未使用
#define SI5351_PLL_RESET    177
#define SI5351_XTAL_LOAD    183


#define REA PORTBbits.RB14 //REinput A INT1
#define REB PORTBbits.RB13 //REinput B
#define SEND PORTAbits.RA7 //TX SEND : H

#define LCD_CS LATBbits.LATB4
#define LCD_DC LATAbits.LATA4
#define LCD_RES LATBbits.LATB7
#define RLED LATAbits.LATA2

#define us unsigned
unsigned long int Freq,MaxFreq,MinFreq,Span,lastFreq,dispfreq;
us int Vcc,lastVcc,timecunt;
us char mojicolor,backcolor,lastSEND;
unsigned int FX,FY;//フォント表示の開始座標
unsigned int GX,GY,GIFx,GIFy;//グラフ表示座標　ピクセルサイズ　x,y
unsigned int F_col,F_row;
us char lcd_digi[10];
us int Hoffset,Voffset;
us char color[17][3];//18bit color data
unsigned char color0[16][3]= {//24bit color data RBG
	{0,0,0},//0 黒
	{255,0,0},//1　赤
	{0,255,0},//2　緑
	{0,100,255},//3　青
	{255,255,0},//4　黄
	{0,255,255},//5　シアン
	{255,0,255},//6　紫
	{255,255,255},//7　白
	{0,0,120},//8　紺
	{120,0,0},//9　茶
	{0,50,0},//10　
	{120,120,0},//11　
	{0,30,50},//12
	{120,0,120},//13
	{60,60,60},//14
	{255,70,0}//15
  
};
static char RE_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static char lastRE = 0; 

// 下記関数宣言は必ず記述する事
 void i2c_init();
 void i2c_start();
 void i2c_stop();
 void i2c_write(unsigned char byte);
 void si5351_write(unsigned char reg, unsigned char data);
 
 void si5351_init();
 void si5351_setpll(unsigned char pll, unsigned char a, unsigned long b, unsigned long c); // PLL逓倍比設定
 void si5351_setms(unsigned char synth, unsigned long div); // Multisynth分周比設定
 void si5351_setfreq(unsigned char channel,unsigned long freq); // si5351への周波数書込み
 
//***************************************************************
//I2C関数
//***************************************************************

void i2c_start() {
    I2C1CONbits.SEN = 1; //スタート条件開始
    while (I2C1CONbits.SEN) {
        //スタート終了待ち
    }
}

void i2c_restart() {
    I2C1CONbits.RSEN = 1; //リスタート条件開始
    while (I2C1CONbits.RSEN) {
        //リスタート終了待ち
    }
}

void i2c_stop() {
    I2C1CONbits.PEN = 1; //ストップ条件開始
    while (I2C1CONbits.PEN) {
        //ストップコンディション終了待ち
    }
}

void i2c_write(unsigned char data) {

    I2C1TRN = data;//dataをレジスタにセット。送信開始
    while (I2C1STATbits.TRSTAT) {
 //       __delay_us(10) ;
        //データの送信終了待ち
    }
}



//*************************************************************************************

void si5351_write(unsigned char reg, unsigned char data)
{
    i2c_start();
    i2c_write(SI5351_I2C_ADDR);
     __delay_us(2) ;
    i2c_write(reg);
    __delay_us(2) ;
    i2c_write(data);
    i2c_stop();
}

void si5351_init() {
	si5351_write(3, 0xFF); // Reg. address 3d(Output Enable Control), All output disable
	si5351_write(16, 0x80); // Reg. address 16d (CLK0 Control), CLK0 power down
	si5351_write(17, 0x80); // Reg. address 17d (CLK0 Control), CLK1 power down
	si5351_write(18, 0x80); // Reg. address 18d (CLK0 Control), CLK2 power down
    si5351_write(SI5351_XTAL_LOAD, 0x80);   // 8pF
}

void si5351_setpll(unsigned char pll, unsigned char a, unsigned long b, unsigned long c)
{
    unsigned long P1;
    unsigned long P2;
    unsigned long P3;

    P1 = 128 * a + (unsigned long)(128 * (float)b / c) - 512;
    P2 = 128 * b - c * (unsigned long)(128 * (float)b / c);
    P3 = c;
    
    si5351_write(pll,     (P3 & 0x0000FF00) >> 8);
    si5351_write(pll + 1, (P3 & 0x000000FF));
    si5351_write(pll + 2, (P1 & 0x00030000) >> 16);
    si5351_write(pll + 3, (P1 & 0x0000FF00) >> 8);
    si5351_write(pll + 4, (P1 & 0x000000FF));
    si5351_write(pll + 5, ((P3 & 0x000F0000) >> 12) | ((P2 & 0x000F0000) >> 16));
    si5351_write(pll + 6, (P2 & 0x0000FF00) >> 8);
    si5351_write(pll + 7, (P2 & 0x000000FF));
}

void si5351_setms(unsigned char synth, unsigned long div)
{
    unsigned long P1;
    unsigned long P2;
    unsigned long P3;

    P1 = 128 * (unsigned long)div - 512;
    P2 = 0;
    P3 = 1;

    si5351_write(synth,     (P3 & 0x0000FF00) >> 8);
    si5351_write(synth + 1, (P3 & 0x000000FF));
    si5351_write(synth + 2, ((P1 & 0x00030000) >> 16));
    si5351_write(synth + 3, (P1 & 0x0000FF00) >> 8);
    si5351_write(synth + 4, (P1 & 0x000000FF));
    si5351_write(synth + 5, ((P3 & 0x000F0000) >> 12) | ((P2 & 0x000F0000) >> 16));
    si5351_write(synth + 6, (P2 & 0x0000FF00) >> 8);
    si5351_write(synth + 7, (P2 & 0x000000FF));
}

void si5351_setfreq(unsigned char channel, unsigned long freq)
{
    unsigned long div;        // synth divider value
    unsigned long pllfreq;    // target PLL frequency
    unsigned char a;        // multisynth a
    unsigned long b;        // multisynth b
    unsigned long c;    // multisynth c
    unsigned long lltmp;    // temporary value

    div = SI5351_PLL_FREQ / freq;     
    div = div >> 1;                // synth divider value is even integer
    div = div << 1; 
    pllfreq = div * freq;            
    c = 0xfffff;                // 20bit denominator max value 
    a = pllfreq / SI5351_XTAL_FREQ;    
    lltmp = pllfreq % SI5351_XTAL_FREQ;
    b  = lltmp * ((float)c / SI5351_XTAL_FREQ);
  
    si5351_write(SI5351_OUTPUT_CTRL, 0xff);

    
    if(channel == 0) {
        si5351_setpll(SI5351_PLL_A, a, b, c);
        si5351_setms(SI5351_MS_0, div);
           
        si5351_write(SI5351_CLK0_CTRL, 0x4f);
        si5351_write(SI5351_PLL_RESET, 0x20); 
    } else {
         si5351_setpll(SI5351_PLL_B, a, b, c);
        si5351_setms(SI5351_MS_1, div);
           
        si5351_write(SI5351_CLK1_CTRL, 0x6f);
        si5351_write(SI5351_PLL_RESET, 0x80); 
    }
    si5351_write(SI5351_OUTPUT_CTRL, 0xFC);
}
 






void lcd_CMD(unsigned char CM) {
//__delay_us(50) ;
    LCD_DC = 0;    
	LCD_CS = 0;
	
	SPI2BUF = CM;
    __delay_us(14) ;
	LCD_CS = 1;
}
void lcd_DATA(unsigned char DA) {
   // __delay_us(150) ;

    LCD_DC = 1;
	LCD_CS = 0;
	
	SPI2BUF = DA;
    __delay_us(14) ;
	LCD_CS = 1;

}
void init_LCD() {
	LCD_RES = 0;
	__delay_ms(120) ;

	LCD_RES = 1;
	__delay_ms(120) ;

    lcd_CMD(0x01);
   
	__delay_ms(120) ;
    
	lcd_CMD(0x11);//Sleep Out
    __delay_us(50) ;
    lcd_CMD(0x28);// display off
	__delay_ms(120) ;
	lcd_CMD(0x36);
     
	lcd_DATA(0b01100100);
    lcd_CMD(0x3A);
	lcd_DATA(0x66);

	lcd_CMD(0x2A);
	lcd_DATA(0x00);
	lcd_DATA(0x00);
	lcd_DATA(0x01);//    01
	lcd_DATA(0xEF);//319 3F
	lcd_CMD(0x2B);
	lcd_DATA(0x00);
	lcd_DATA(0x00);
	lcd_DATA(0x00);//     00
	lcd_DATA(0x3F);//239  EF

//	lcd_CMD(0x29);//Display ON
//	lcd_CMD(0x2C);
	__delay_ms(100) ;
	
}



void itostring(unsigned char digit, unsigned long int data,unsigned  char *buffer) {
	unsigned char i;
	buffer += digit;
	*buffer =0;					// 最後の数字位置
	for(i=digit; i>0; i--) {			// 変換は下位から上位へ
            buffer--;					// ポインター１
            *buffer = (data % 10) + '0';	// ASCIIへ
            data = data / 10;				// 次の桁へ
	}
}
void set_col_range(unsigned int start, unsigned int end) {//行範囲の指定
	lcd_CMD(0x002A);
	lcd_DATA(start >> 8);
	lcd_DATA(start);
	lcd_DATA(end >> 8);
	lcd_DATA(end);
	}
void set_row_range(unsigned int start, unsigned int end) {//列範囲の指定
	lcd_CMD(0x002B);
	lcd_DATA(start >> 8);
	lcd_DATA(start);
	lcd_DATA(end >> 8);
	lcd_DATA(end);
	}

void set_LCDcolor(unsigned char C) {//24bitRGB?16bitRGB
	unsigned int c0;
    us int cr,cg,cb;
    c0 = 0;
//	cr =255- color0[C][0];//赤
	cr = color0[C][0];//赤
//	cg =255- color0[C][1];//緑 
	cg = color0[C][1];//緑 
    
	
//	cb =255- color0[C][2];//青
	cb = color0[C][2];//青

	color[C][0] = cr;
	color[C][1] = cg;
    color[C][2] = cb;
}

void makecolorList(){
	us char i;
	for (i = 0;i <= 15;i++){
		set_LCDcolor(i);
	}
}
void write_color(unsigned char C) {
	lcd_DATA(color[C][0]);
	lcd_DATA(color[C][1]);
    lcd_DATA(color[C][2]);
}

void mojidisp0( void *fp) {//FONT形式のグラフィック表示(ブロック文字)
    const unsigned char *fc = (const unsigned char*)fp;
	unsigned int k;
	unsigned int x,y,m;
 	set_col_range(FX,FX+F_col);
 	set_row_range(FY,FY+F_row);
 	lcd_CMD(0x2C);//色データ書き込み
        m=0;
 	for (y=0;y<=F_row;y++) {
 		for (x=0;x<=F_col;x++) {
 			k=(*fc) & (1<<(7-m));
 				if (k>0) {
                    write_color(mojicolor);//文字色
 				} else {
                    write_color(backcolor);//背景色
 				}
                        m++;
                        if (m>7) {
                            m=0;
                            if (x < F_col) {fc++;}
                        }
 			}
                m=0;fc++;
 	}
}




void select_font_mk2(unsigned int F) {
    switch (F) {
        case  7:F_col=6;F_row=9;break;//実際のフォントドットから-1した値
        case 22:F_col=21;F_row=43;break;
        case  9:F_col=8;F_row=14;break;
    }
}
void mojidisp_mk2(us char f,us char ch,us char spn) {//BLOCK文字表示
	int k;
    const unsigned char *fc;
	int x,y,ma,mj;

	set_col_range(FX,FX+F_col);
 	set_row_range(FY,FY+F_row);
 	lcd_CMD(0x2C);//色データ書き込み

    switch (f) {
//        case 7:fc = Font7_table[ch];break;
		case 9:fc = Font9_table[ch];break;
//        case 12:fc = Font12_table[ch];break;
    	case 22:fc = Font22_table[ch];break;
     }

	mj = F_col;

 	for (y=0;y<=F_row;y++) {
 		mj = F_col;
 		for (x=0;x<=F_col;x++) {
 			ma = mj % 8;//ma:mjを8で割り算した余り
 			k=(*fc) & (1<< ma);
 				if (k>0) {
                    write_color(mojicolor);//文字色
 				} else {
 					write_color(backcolor);//背景色
					
 				}
                mj--;
                if (ma == 0) {if (x < F_col) {fc++;}}
 			}
                
 		fc++;
 	}
	FX=FX+F_col+spn;
}


void mojiretsudisp_mk2( us int x,us int y,us char fnt,  us char *str,us char spn) {//  文字列表示
    unsigned char i;
    char len;
	FX = x; FY =y;
	select_font_mk2(fnt);
	len = strlen(str);
	for (i=0;i<len;i++) {
        mojidisp_mk2(fnt,str[i],spn);
	}
}


void write_dots(int x,int y,int d,char c) {//x:ｘ座標　y:y座標　d:線幅　c:色番号
	int i,j;
	set_col_range(x,x+d);
 	set_row_range(y,y+d);
	lcd_CMD(0x2C);//色データ書き込み
	for (i=x;i<x+d;i++) {
 		for (j=y;j<=y+d;j++) {
 			write_color(c);//文字色
 		}
	}
}


void integerdisp(us int x, us int y,us char fnt,us char degi, us long int num,us char spn) {
    FX=x;FY=y;
    itostring(degi,num,lcd_digi);//ASCIIに変換
    mojiretsudisp_mk2(x,y,fnt,lcd_digi,spn);
}


void write_line(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye,unsigned char c) {
    unsigned int i,j;
    set_col_range(xs,xe);
    set_row_range(ys,ye);
    lcd_CMD(0x2C);//色データ書き込み
    for (i=ys;i<=ye;i++) {
        for (j=xs;j<=xe;j++) {
            write_color(c);
        }
    }
}
void write_Rectangle(us int xs,us int ys,us int xe,us int ye,us int c) {
    us int i,j;
    write_line(xs,ys,xe,ys,c);
    write_line(xs,ys,xs,ye,c);
    write_line(xe,ys,xe,ye,c);
    write_line(xs,ye,xe,ye,c);
}

int get_colorcord(unsigned int R,unsigned int G,unsigned int B){
    int i,j;
    i=R>>3;
    i=i<<6;
    j=G>>2;
    i=i|j;
    i=i<<5;
    j=B>>3;
    i=i|j;
    return i;
}

unsigned int takeADdata() {
  	unsigned int adv;
    AD1CON1bits.SAMP = 1;//AD Start
    while (!AD1CON1bits.DONE);

    adv =  ADC1BUF0;

	return adv;
}

void dispFreq(){
	us char dg,fxm;
//    fxm = 1;
	dg = 5;fxm =28;
	if (Freq > 7999999){dispfreq = Freq;} else { dispfreq = Freq/100;dg = 5;}//Xs,Ys,Xe,Ye,Color
	
	mojicolor=4;integerdisp(fxm+Hoffset, 20+Voffset,22,dg, dispfreq, 7);//FX,FY,Font番号,桁数,数値,スパン
}
void dispVcc(){
	mojicolor=7;integerdisp(180+Hoffset, 38+Voffset,9,3, Vcc, 5);//FX,FY,Font番号,桁数,数値,スパン
	
}
////////////////////////////////////////////////////////


void __attribute__((__interrupt__,__no_auto_psv__)) _T1Interrupt(void){
	unsigned char k;          
    char curRE;
 	IFS0bits.T1IF = 0;
 	IEC0bits.T1IE = 0;
  	T1CONbits.TON = 0;// ti タイマー1 Stop
/*	curRE = REB * 2 + REA;    
    lastRE <<= 2;                      
    lastRE |= ( curRE & 0x03 ); 
    k = (RE_table[(lastRE & 0x0F)]);
	if ((k == 1) && (Freq < MaxFreq) ){Freq = Freq + Span;} 
	if ((k == 255) && (Freq > MinFreq)){Freq = Freq - Span;}
	*/
 	TMR1 = 0;
    timecunt++;
  	T1CONbits.TON = 1;// ti タイマー1スタート

 	IEC0bits.T1IE = 1;

}

void __attribute__((__interrupt__,__no_auto_psv__)) _INT1Interrupt(void){//周波数データ

 IFS1bits.INT1IF = 0;
 IEC1bits.INT1IE = 0;
	 
       if (REB == 0) {
            if (Freq < MaxFreq) {Freq = Freq + Span;}
       }
 		if (REB == 1) {
			if (Freq > MinFreq) {Freq = Freq - Span;}
       }
 IEC1bits.INT1IE = 1;
 __delay_ms(30); 
}


///////////////////////////////////////////////////////////////////

 int main()  {
 unsigned int i,j;
 OSCCON = 0b0001000100000100; //Fosc FRCPLL 32MHz
 CLKDIV = 0x0000;
 ANSA = 0b00000000000000001;//RA0→AN  0x00031
 TRISA =0b0000000011101011; //ポートA　入出力設定
 PORTA = 0x0000;
 ANSB = 0x0000;
 TRISB = 0b0111011100000011;
 
 //AD1CSSL = 0b0000000000000001;//AN0 SCAN有効 0x0001
 AD1CON1 = 0b0010000001110000;//AD Idleモードで停止 12bit 自動変換
 AD1CON2 = 0b0000000000000000;//Buffペア使用　入力をスキャン　MUX-Aのみ使う　フラグは5回サンプルしたら立てる
 AD1CON3 = 0b0001111100000111;
 AD1CHS = 0;//スキャン開始AN0　負側入力Vss
 AD1CON1bits.ADON =1;
 //SPI2CON1 = 0b0000000001110011;//マスターモード クロック second 1/4 primaly 1/4 (clk=1MHz)
 SPI2CON1 = 0b0000000001100011;//マスターモード クロック second 1/8 primaly 1/4 (clk=500KHz)
 SPI2CON2 = 0x0000;
 SPI2STATbits.SPIROV = 0;
 SPI2STATbits.SPIEN = 1;//SPI2有効化
 
 I2C1CONbits.I2CEN = 1;
 I2C1BRG = 157;
 I2C1MSK = 0;

 	
INTCON1 = 0x0000;
 INTCON2 = 0x0000;//INT1 立下りで割り込み
 IFS1bits.INT1IF = 0;
 IEC1bits.INT1IE = 1;//INT1 割り込み可
 
 	
 T1CON = 0b0000000000100000;//Timer1：プリスケーラー1/64 クロック：fosc/2  
 PR1 = 1000;//T1 カウントmax 1msごとに割り込み発生
 TMR1 = 0;//T1レジスタクリア
 IPC0bits.T1IP = 3;//t1 割込み優先度　3
 IFS0bits.T1IF = 0;//t1 割込みフラグクリア
 IEC0bits.T1IE = 1;//t1 割込み許可
 T1CONbits.TON = 1;// ti タイマースタート


 
MaxFreq = 7300000;MinFreq = 7000000;Span = 1000;Freq = 7195000;
//MaxFreq = 10000500;MinFreq = 9999500;Span = 1;Freq = 10000000;
//__delay_ms(5);
if (SEND == 1){si5351_setfreq(0,Freq);} else {si5351_setfreq(0,7300000);}
//si5351_setfreq(0,Freq);//VFO freq
makecolorList();
init_LCD();//LCD初期設定

//***********************************画面クリアー（8番色(青)で全面塗りつぶし）
lcd_CMD(0x002C);//色データ書き込み

    lcd_CMD(0x29);//Display ON
 	Hoffset = 43;Voffset = 75;

	write_line(0,80,319,165,8);//Xs,Ys,Xe,Ye,Color 	
//    mojiretsudisp_mk2(220+Hoffset,48+Voffset,9,"Hz",1);// ;backcolor = 8;

    write_Rectangle(20+Hoffset,14+Voffset,170+Hoffset,74+Voffset,4);//xs,ys,xe.ye,color
    write_Rectangle(175+Hoffset,14+Voffset,220+Hoffset,74+Voffset,4);//xs,ys,xe.ye,color
    mojicolor=5;mojiretsudisp_mk2(180+Hoffset,20+Voffset,9,"VDD",5);//
    mojicolor=7;write_dots(203+Hoffset,52+Voffset,2,7);//x,y,size,color
    mojicolor=5;mojiretsudisp_mk2(206+Hoffset,55+Voffset,9,"v",5);//
    lastFreq = 0;lastVcc = 0;lastSEND = 0;
    mojicolor=4;
    write_dots(52+Hoffset,62+Voffset,4,4);
    write_dots(135+Hoffset,62+Voffset,4,4);
 	//    周波数単位の表示
    F_col=14;F_row=4;//Font5G KHz MHz
    mojicolor=5;
    backcolor = 8;
    FX=50+Hoffset;FY=67+Voffset;
    mojidisp0(&Font5G_MHz);
    FX=133+Hoffset;FY=67+Voffset;
    mojidisp0(&Font5G_KHz);
 	

    lastFreq = Freq;
    dispFreq();
    while(1){
        RLED = ~RLED;
    	if (lastFreq != Freq){

    		si5351_setfreq(0,Freq);//VFO freq
    		dispFreq(); 
    		lastFreq = Freq;

    	}
        if (timecunt > 250){
            Vcc = takeADdata();timecunt = 0;dispVcc();}

    	if (lastSEND != SEND) {
    		if (SEND == 1){si5351_setfreq(0,Freq);} else {si5351_setfreq(0,7300000);}//VFO freq
    		lastSEND = SEND;
         //   dispFreq();
    	}
    };
	

}
