/* * File: Mp3_13.c * * Created on 2018/11/06, 20:23 */ #include <18F26K22.h> #device ansi #device const=read_only #device PASS_STRINGS=IN_RAM #opt compress #fuses INTRC_IO,NOPLLEN,NOFCMEN,NOIESO,NOBROWNOUT,NOWDT,NOPBADEN,NOMCLR,STVREN,NOLVP,NOXINST,NOCPB,NOCPD,NODEBUG,CCP3B5 #use delay (clock=8000000) #include #include typedef unsigned int8 uint8_t; typedef unsigned int16 uint16_t; typedef unsigned int32 uint32_t; // 電源 #define PIN_PLOCK PIN_C6 // (output) #define PIN_PDOWN PIN_B4 // detect power off (input) #define PIN_DIRECT_PDON PIN_B0 // Raspbery PI へのPower Down指示 #define PIN_LED PIN_B5 // LCD #define PIN_LCD_DI PIN_C5 #define PIN_LCD_RW PIN_A0 #define PIN_LCD_E PIN_A1 #define PIN_LCD_D0 PIN_A2 #define PIN_LCD_D1 PIN_A3 #define PIN_LCD_D2 PIN_A4 #define PIN_LCD_D3 PIN_A5 #define PIN_LCD_D4 PIN_C4 #define PIN_LCD_D5 PIN_A7 #define PIN_LCD_D6 PIN_A6 #define PIN_LCD_D7 PIN_C0 #define PIN_LCD_CS1 PIN_C1 #define PIN_LCD_CS2 PIN_C2 #define PIN_LCD_RESET PIN_C3 #define PIN_LCD_BKLT PIN_C7 // バックライト制御 /* 各制御線を操作するためのマクロ */ #define GLCD_RS_H output_high(PIN_LCD_DI) // PORT_LCD_CTRL|=(1<= ACTIVE_TIMEOUT){ output_low(PIN_DIRECT_PDON); break; } } while (1); program_end: GLCD_BKLT_ON; LedBlinkFlg = 1; // Blink開始 LedBlinkTimer = 0; wait_ms(15000); // RaspberryPIの停止を待つ output_low(PIN_PLOCK); while (1){ } return (0); } void InitApp(){ /* Initialize peripherals */ setup_adc(ADC_OFF); // ADC disabled setup_ccp1(CCP_OFF); // CCP1 disabled setup_ccp2(CCP_OFF); // CCP2 disabled setup_ccp3(CCP_OFF); // CCP3 disabled setup_oscillator(OSC_8MHZ); output_high(PIN_PLOCK); port_b_pullups(0x10); // B4=PIN_PDOWN output_float(PIN_PDOWN); output_low(PIN_LCD_D0); output_low(PIN_LCD_D1); output_low(PIN_LCD_D2); output_low(PIN_LCD_D3); output_low(PIN_LCD_D4); output_low(PIN_LCD_D5); output_low(PIN_LCD_D6); output_low(PIN_LCD_D7); output_low(PIN_LCD_CS1); output_low(PIN_LCD_CS2); output_low(PIN_LCD_RESET); output_low(PIN_LCD_DI); output_low(PIN_LCD_RW); output_low(PIN_LCD_E); GLCD_BKLT_OFF; LedBlinkFlg = 1; LedBlinkTimer = 0; ActiveTimer = 0; // タイマーイベントハンドラが呼ばれる周期 // Timer0 : (4/8MHz) * 2(prescaler) = 1us // 1us * 65536 = 65.5ms (TIMER0_INIT=0のとき) // 1us * (65536 - 15536) = 50.0ms (TIMER0_INIT=15536のとき) setup_timer_0(T0_INTERNAL | T0_DIV_2); set_timer0(TIMER0_INIT); clear_interrupt(INT_TIMER0); enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); // (1000us)/(4/8MHz)*250 = 8 // -> 8*delay_cycle(250) = 1ms WaitMsCycle = 8; glcd_init(); /* 液晶モジュールの初期化 */ //setup_spi2(SPI_SLAVE | SPI_MODE_0); // NG setup_spi2(SPI_SLAVE | SPI_MODE_1 | SPI_SS_DISABLED); // OK } /* glcd_write() 液晶モジュールにデータを送ります. 予め送信先チップを選択しておく必要があります. */ void glcd_write(uint8_t cmd) { GLCD_RW_L; GLCD_E_H; //PORT_LCD_DATA=cmd; output_bit(PIN_LCD_D0, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D1, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D2, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D3, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D4, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D5, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D6, (cmd & 0x01)); cmd >>= 1; output_bit(PIN_LCD_D7, (cmd & 0x01)); //_delay_us(6); GLCD_E_L; //_delay_us(2); } /* glcd_cls() 画面を消去します. 予め送信先チップを選択しておく必要があります. */ void glcd_fill(uint8_t patt) { uint8_t x,y; for(y=0;y<8;y++){ GLCD_SETPAGE(y); GLCD_SETADRS(0); for(x=0;x<64;x++){ GLCD_DATA(patt); } } } /* glcd_init() 液晶ディスプレイの初期化を行います. 2個のチップを別々に初期化します. */ void glcd_init(void) { GLCD_RST_H; /* リセットを解除 */ //_delay_ms(30); /* 30ms(以上)ウェイト */ wait_ms(30); GLCD_CS1_H; /* 左半分担当チップ */ GLCD_STRTLNE(0); /* 表示開始位置のセット */ glcd_fill(0xFF); /* ピクセルテスト用に全部点灯*/ GLCD_CS1_L; GLCD_CS2_H; /* 右半分担当チップ */ GLCD_STRTLNE(0); /* 上と同じ */ glcd_fill(0xFF); GLCD_CS2_L; GLCD_CS1_H; /* 左半分担当チップ */ GLCD_DISP_ON; /* メモリ内容を表示する */ GLCD_CS1_L; GLCD_CS2_H; /* 右半分担当チップ */ GLCD_DISP_ON; /* 上と同じ */ GLCD_CS2_L; } void disp_lcd(){ uint8_t buf,x,y; uint16_t cnt=0; for(y=0; y