// CONFIG #pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled) #pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR) #pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3/PGM pin has digital I/O function, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EE Memory Code Protection bit (Code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off) #pragma config CCPMX = RB2 // CCP1 Pin Selection bit (CCP1 function on RB2) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off #include #include #include "skSD1602LCD.h" #define _XTAL_FREQ 8000000 //8MHz #define CLK RB0 #define DAT RB1 #define LCD_RS RB2 #define LCD_EN RB3 #define LCD_D4 RB4 #define LCD_D5 RB5 #define LCD_D6 RB6 #define LCD_D7 RB7 #define WAIT_HIGH while(CLK == 0); #define WAIT_LOW while(CLK == 1); char getCharacter(); void main(void) { OSCCON = 0b01110000; //周波数8MHz OPTION_REGbits.nRBPU = 0; //PORTBを内部プルアップ ADCON0 = 0b00000000; //ADコンバータOFF ADCON1 = 0b00000110; //RA2 RA3 Vref使わない TRISA = 0b00000000; //全て出力 TRISB = 0b00000011; //RB0 RB1入力 PORTA = 0b00000000; //全てLOWにする PORTB = 0b00000011; char ch; lcd_init() ; lcd_clear(); while(1) { if(CLK == 0) //スタートビット { ch = getCharacter(); switch(ch & 0xf0) { case 0x80: lcd_setCursor(ch & 0xf, 0); break; case 0x90: lcd_setCursor(ch & 0xf, 1); break; default: lcd_putc(ch); break; } } } } char getCharacter() { unsigned char val, bi; val = 0; WAIT_HIGH for(int n = 0; n < 8; n++) { WAIT_LOW bi = DAT; val |= bi << n; WAIT_HIGH } return val; }