我申请的AVR小板换成PIC18了。
今天搞了一下HT1621
代码如下:
// CONFIG1L
#pragma config FEXTOSC = ECH // External Oscillator mode Selection bits (EC (external clock) above 8 MHz; PFM set to high power)
#pragma config RSTOSC = EXTOSC // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits (device manufacturing default))
// CONFIG1H
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
// CONFIG2L
#pragma config MCLRE = EXTMCLR // Master Clear Enable bit (MCLR pin (RE3) is MCLR)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (Power up timer disabled)
#pragma config LPBOREN = OFF // Low-power BOR enable bit (Low power BOR is disabled)
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled , SBOREN bit is ignored)
// CONFIG2H
#pragma config BORV = VBOR_190 // Brown Out Reset Voltage selection bits (Brown-out Reset Voltage (VBOR) set to 1.90V)
#pragma config ZCD = OFF // ZCD Disable bit (ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)
// CONFIG3L
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT Disabled)
// CONFIG3H
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)
// CONFIG4L
#pragma config WRT0 = OFF // Write Protection Block 0 (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection Block 1 (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection Block 2 (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection Block 3 (Block 3 (00C000-00FFFFh) not write-protected)
#pragma config WRT4 = OFF // Write Protection Block 4 (Block 4 (010000-013FFFh) not write-protected)
#pragma config WRT5 = OFF // Write Protection Block 5 (Block 5 (014000-017FFFh) not write-protected)
#pragma config WRT6 = OFF // Write Protection Block 6 (Block 6 (018000-01BFFFh) not write-protected)
#pragma config WRT7 = OFF // Write Protection Block 7 (Block 7 (01C000-01FFFFh) not write-protected)
// CONFIG4H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-30000Bh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
#pragma config SCANE = ON // Scanner Enable bit (Scanner module is available for use, SCANMD bit can control the module)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)
// CONFIG5L
#pragma config CP = OFF // UserNVM Program Memory Code Protection bit (UserNVM code protection disabled)
#pragma config CPD = OFF // DataNVM Memory Code Protection bit (DataNVM code protection disabled)
// CONFIG5H
// CONFIG6L
#pragma config EBTR0 = OFF // Table Read Protection Block 0 (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection Block 1 (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection Block 2 (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection Block 3 (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR4 = OFF // Table Read Protection Block 4 (Block 4 (010000-013FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR5 = OFF // Table Read Protection Block 5 (Block 5 (014000-017FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR6 = OFF // Table Read Protection Block 6 (Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR7 = OFF // Table Read Protection Block 7 (Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks)
// CONFIG6H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <pic18f47q10.h>
#define Smg_a 0x80
#define Smg_b 0x40
#define Smg_c 0x20
#define Smg_d 0x01
#define Smg_e 0x02
#define Smg_f 0x08
#define Smg_g 0x04
#define Smg_dp 0x10
#define Bmp0Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map Smg_b | Smg_c
#define Bmp2Map Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map Smg_a | Smg_b | Smg_c
#define BmpAMap Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap Smg_a | Smg_e | Smg_f | Smg_g
#define CS_0 RD0=0
#define CS_1 RD0=1
#define WR_0 RD1=0
#define WR_1 RD1=1
#define DA_0 RD2=0
#define DA_1 RD2=1
#define DELAYCONST 3
const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //显示缓冲区
//unsigned int i;
void delay(unsigned char x)
{
unsigned char i;
for(i=x;i>0;i--);
}
void COMMAND_HT1621(unsigned char comm)
{
unsigned char i;
CS_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
for(i=0;i<3;i++) //写命令
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<9;i++) //写命令数据
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
CS_1;
}
void HT1621_Display(void)
{
unsigned char i;
CS_0; //片选CS
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
for(i=0;i<3;i++) //写命令
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<6;i++) //写地址
{
if((20<<i)&0x20) DA_1; //20对应 SEG地址
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
delay(DELAYCONST);
WR_0;
delay(DELAYCONST);
WR_1;
delay(DELAYCONST);
}
CS_1; //释放CS
}
void LCD_Init(void)
{
COMMAND_HT1621(0x01); //SYS EN
COMMAND_HT1621(0x03); //LCD ON
COMMAND_HT1621(0x29); //4 COM 1/3 BIAS
HT1621_Display(); //clear screen
}
void main(void)
{
TRISD=0;
ANSELD=0;
ODCOND=0;
SLRCOND=0;
ADCON0=0;
//WPUE=0x04;
LCD_Init();
DpyNum[0] = Smg_a|Smg_d|Smg_g; //"三"
DpyNum[1] = SegCode[1];
DpyNum[2] = SegCode[3];
DpyNum[3] = SegCode[5];
DpyNum[4] = SegCode[7];
DpyNum[5] = SegCode[9];
HT1621_Display(); //刷新LCD
while(1)
{
}
return;
}
效果图:
|