#include /* common defines and macros */ #include /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12dp512" //************128x64 cog module************************* //#include //#include //****************************************************** //sbit cs =P2^4; //sbit rst =P2^3; //sbit a0 =P2^2; //sbit di =P2^0; //sbit scl =P2^1; #define cs PORTK_BIT0 #define rst PORTK_BIT1 #define a0 PORTK_BIT2 #define di PTS_PTS5 #define scl PTS_PTS6 //****************************************************** //#define nop() asm nop unsigned char tab1[]= { 0xFF,0xFF,0xFF,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07, 0x07,0x07,0x07,0x87,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0x87, 0x87,0x07,0x07,0x07,0x07,0x87,0x87,0x87,0x87,0x87,0x07,0x07,0x07,0x07,0x07,0x07, 0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0x07,0x07,0x07,0x07,0x07,0x87,0x07,0x07, 0x07,0x07,0x87,0x87,0x87,0x07,0x07,0x07,0x07,0x87,0x87,0x87,0x87,0x87,0x07,0x07, 0x07,0x07,0x87,0x07,0x07,0x07,0x07,0x07,0x87,0x07,0x07,0x87,0x07,0x07,0x07,0x07, 0x07,0x07,0x07,0x07,0x87,0x87,0x87,0x87,0x87,0x87,0x87,0x07,0x07,0x07,0x07,0x07, 0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x03,0x00,0x00, 0x00,0x01,0x86,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x03,0xFC,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x0F,0xF0,0x00,0xF0,0x0F,0xFF,0x00,0x00, 0xFE,0x01,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x03,0xFC, 0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0x04,0x04,0xC4,0xC4,0xC4,0xC4,0xC0,0x00,0x01,0xC2,0xC4,0xC4, 0xC4,0xC2,0x01,0x00,0x00,0x07,0x04,0x04,0x84,0xC4,0xC3,0xC0,0x00,0x00,0xC0,0xC0, 0xC0,0x80,0x80,0x00,0x00,0x00,0xC0,0xC7,0xC0,0xC1,0xC6,0xC1,0xC0,0x47,0x00,0x00, 0x01,0x02,0x04,0x04,0x04,0x02,0x01,0xC0,0xC0,0xC7,0xC4,0xC4,0xC4,0xC4,0x03,0x00, 0xC0,0xC0,0xC1,0xC2,0xC4,0x04,0x04,0x42,0xC1,0xC0,0xC0,0xC7,0xC4,0x84,0x04,0x04, 0x04,0x44,0xC0,0xC0,0xC7,0x44,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x01,0x80,0xE0,0xF0,0xFC,0xFF,0x7F,0x1F,0x07, 0x03,0x00,0xC0,0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x01, 0x8F,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x30, 0x38,0xFC,0x00,0x87,0x8F,0x00,0x00,0x00,0xF8,0xF1,0x03,0x0F,0x1F,0x3F,0xFF,0xFE, 0xF8,0xF0,0xE3,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x80,0x00,0x80,0x00,0x8C,0x8E,0x0F,0x8F,0x0F,0x83,0x80,0x08,0x8C,0x0C, 0x8E,0x0F,0x0F,0x00,0x00,0x00,0x80,0x83,0x87,0x87,0x0F,0x0E,0x8C,0x80,0x0C,0x0E, 0x0F,0x07,0xF7,0x03,0x00,0x00,0x8C,0x8F,0x8F,0x0F,0x8F,0x8F,0x80,0x80,0x00,0x8C, 0xEC,0x8C,0x8F,0x0F,0x00,0x80,0x80,0x88,0x0F,0x0F,0x8F,0x8F,0x8F,0x00,0xF0,0x88, 0x8C,0x8C,0x0C,0x0F,0x0F,0x00,0x08,0x0C,0x0F,0x8F,0x8C,0x88,0x00,0x00,0x80,0x81, 0x03,0x07,0x8F,0x8F,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x80,0xC1,0x07,0x00,0x07,0x01,0x01,0x07,0x80,0x47,0x41,0x41,0x87,0x00,0x07, 0x01,0x00,0x84,0x40,0x40,0x40,0x84,0x06,0x05,0x44,0x80,0x03,0x04,0x04,0x03,0x00, 0x80,0x40,0x07,0x00,0x80,0x43,0x45,0x45,0x45,0x80,0x07,0x00,0x00,0x07,0x00,0x00, 0xC7,0xC4,0x04,0x00,0x03,0x05,0x05,0x05,0x00,0x03,0x04,0x04,0x02,0x00,0xC7,0x40, 0x40,0x47,0x40,0x80,0x04,0x00,0x00,0x00,0x83,0x44,0x44,0x42,0x80,0x03,0x04,0x04, 0x43,0x40,0x47,0xC0,0x47,0x40,0x47,0x00,0x00,0x80,0x40,0x40,0x40,0x40,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x40,0x20,0x10,0x08,0x07,0x00, 0x00,0xE3,0x14,0x08,0x08,0x08,0x14,0xE3,0x00,0x00,0x00,0xC3,0x24,0x18,0x24,0xC3, 0x00,0x00,0x00,0xFE,0x09,0x04,0x04,0x04,0x08,0xF1,0x00,0x00,0x60,0x58,0x44,0x43, 0x40,0xFF,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00, 0x00,0x00,0x00,0x81,0x7E,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xC3,0x04,0x08,0x08,0x10,0x10,0x10,0xE1, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0, 0xE0,0xE0,0xE3,0xE0,0xE0,0xE0,0xE0,0xE0,0xE3,0xE2,0xE2,0xE2,0xE2,0xE2,0xE2,0xE0, 0xE0,0xE0,0xE1,0xE2,0xE2,0xE2,0xE1,0xE0,0xE0,0xE2,0xE1,0xE0,0xE0,0xE0,0xE0,0xE0, 0xE1,0xE2,0xE0,0xE0,0xE1,0xE2,0xE2,0xE2,0xE1,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0, 0xE0,0xE3,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE3,0xE2, 0xE2,0xE2,0xE2,0xE1,0xE0,0xE0,0xE0,0xE0,0xE1,0xE2,0xE2,0xE2,0xE1,0xE0,0xE0,0xE0, 0xE0,0xE0,0xE0,0xE3,0xE0,0xE0,0xE0,0xE0,0xE0,0xE1,0xE2,0xE2,0xE2,0xE2,0xE1,0xE0, 0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0xFF,0xFF, }; //**************delay************************************ void delay_nms(unsigned int n) { unsigned int i,j; for(i=n;i>0;i--) { for(j=1000;j>0;j--) { } } } void MCUInit(void)//芯片初始化(了解更多请阅读S12在线开发相关章节介绍) { asm sei //asm CLR $0011 REFDV=0x01; // initiate PLL clock SYNR =0x02; // system clock 24M while (!(CRGFLG & 0x08)){} //CRGFLG的D3=1则稳定,并且可做为系统时钟 CLKSEL=0x80; // 选定所相环时钟 //FCLKDIV=0x49; //使FLASH 和 EEPROM // 的擦除操作工作频率在200HZ左右 //ECLKDIV=0x49; //PPAGE=0x20; SCI0BD=0x009C; //SCI0BDL=0x9c; SCI0CR2=0x2c;// asm cli } //***************send_data******************************** void data_send(unsigned char dat) { unsigned char s,temp; int i; scl=0; s=dat; for(i=8;i>0;i--) { scl=0; asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop temp=s&0x80; if(temp) {di=1; } else {di=0; } asm nop asm nop asm nop asm nop asm nop asm nop asm nop scl=1; asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop s=s<<1; } } //***************write command***************************** void wr_com(unsigned char com) { a0=0; cs=0; data_send(com); cs=1; } //***************write data******************************** void wr_data(unsigned char dat) { a0=1; cs=0; data_send(dat); cs=1; } //********************************************************** void display_kuang() { unsigned char seg; unsigned char page; for(page=0xb0;page<0xb8;page++) { if(page==0xb0) { wr_com(page); wr_com(0x10); wr_com(0x00); for(seg=0;seg<128;seg++) { if(seg==0) wr_data(0xff); else if(seg==127) wr_data(0xff); else wr_data(0x01); } } else { if(page==0xb7) { wr_com(page); wr_com(0x10); wr_com(0x00); for(seg=0;seg<128;seg++) { if(seg==0) wr_data(0xff); else if(seg==127) wr_data(0xff); else wr_data(0x80); } } else { wr_com(page); wr_com(0x10); wr_com(0x00); for(seg=0;seg<128;seg++) { if(seg==0) wr_data(0xff); else if(seg==127) wr_data(0xff); else wr_data(0x00); } } } } } //********************************************************** void display_lattice(unsigned char dat1,unsigned char dat2) { unsigned char seg; unsigned char page; for(page=0xb0;page<0xb7;page++) { wr_com(page); wr_com(0x10); wr_com(0x00); for(seg=0;seg<128;seg++) { if(seg<64){ wr_data(0x00); }else{ wr_data(0xff); } //wr_data(0x00); } } } //********************************************************** //********************************************************** void display_map(unsigned char *p) { unsigned char seg; unsigned char page; for(page=0xb0;page<0xb8;page++) { wr_com(page); wr_com(0x10); wr_com(0x00); for(seg=0;seg<128;seg++) { wr_data(*p); ++p; } } } //********************************************************** void main(void) { MCUInit(); DDRK=0xff; DDRS=0xff; EnableInterrupts; rst=1; delay_nms(1000); rst=0; delay_nms(6000); rst=1; delay_nms(1000); DDRB=0xff; //**********lcd inintial************ // wr_com(0xae); wr_com(0xa0); //ADC normal wr_com(0xc8); //com normal wr_com(0xa2); //set partial display duty 1/65 // wr_com(0x2c); //vc on // delay_nms(1000); // wr_com(0x2e); //vr on // delay_nms(1000); wr_com(0x24); //wr_com(0x26); //set rb/ra=5.29 wr_com(0x81); //set reference voltage select wr_com(0x21); wr_com(0x2f); //internal booster,follower,divided on wr_com(0xa4); delay_nms(1000); wr_com(0xaf); wr_com(0xf8); wr_com(0x00); wr_com(0x40); //set start line 00 delay_nms(1000); //************************************ while(1) { delay_nms(2000); display_map(tab1); // display_map(tab1); // delay_nms(2000); // display_lattice(0x00,0x00); // delay_nms(2000); //wr_com(0xa5); /* display_kuang(); delay_nms(2000); display_lattice(0x55,0x55); delay_nms(2000); display_lattice(0x00,0xff); delay_nms(2000); display_lattice(0x55,0xaa); delay_nms(2000); */ PORTB=~PORTB; delay_nms(6000); // y--; } }