资料
  • 资料
  • 专题
开源Mega8玩转SPI接口TFT彩屏
推荐星级:
时间:2019-12-23
大小:783.02KB
阅读数:208
上传用户:二不过三
查看他发布的资源
下载次数
0
所需E币
3
ebi
新用户注册即送 300 E币
更多E币赚取方法,请查看
close
资料介绍
做了个spi接口的TFT彩屏的转接板 在上面顺便放了个MEGA8以及USB接口 mega8的引脚几乎都引出来了 自己觉得SPI接口的彩屏很有玩头 准备全部开源 欢迎拍砖 以便于提高一下自己的软硬件水平最简单的屏的DEMO代码 RGB3基色显示 //ICC-AVRapplicationbuilder:2008-11-211:21:49 //Target:M8 //Crystal:8.0000Mhz #includeiom8v.h> #includemacros.h> //Signalbitdefinitions #definelcd_cs3//PB3 #definelcd_rst2//PB2 #definelcd_cd4//PB4 #definelcd_dta4//PC4 #definelcd_clk5//PC5 #defineSetLcdA0PORTB|=(1lcd_cd); #defineClrLcdA0PORTB=~(1lcd_cd); #defineSetLcdWRPORTC|=(1lcd_clk); #defineClrLcdWRPORTC=~(1lcd_clk); #defineSetledPORTB|=(15); #defineClrledPORTB=~(15); #defineSetLcdRSTPORTB|=(1lcd_rst); #defineClrLcdRSTPORTB=~(1lcd_rst); #defineSetLcdCSPORTB|=(1lcd_cs); #defineClrLcdCSPORTB=~(1lcd_cs); #defineSetLcdSdataPORTC|=(1lcd_dta); #defineClrLcdSdataPORTC=~(1lcd_dta); voidport_init(void) { PORTB=0x00; DDRB=0xFF; PORTC=0x00;//m103outputonly DDRC=0x7F; PORTD=0x00; DDRD=0xFF; } //callthisroutinetoinitializeallperipherals voidinit_devices(void) { //stoperrantinterruptsuntilsetup CLI();//disableallinterrupts port_init(); MCUCR=0x00; GICR=0x00; TIMSK=0x00;//timerinterruptsources SEI();//re-enableinterrupts //allperipheralsarenowinitialized } voidDelay_1us(void)//1us延时函数 { asm("nop"); } voidDelay_nus(unsignedintn)//Nus延时函数 { unsignedinti=0; for(i=0;in;i++) Delay_1us(); } voidDelay_1ms(void)//1ms延时函数 { unsignedinti; for(i=0;i1140;i++); } voidDelay_nms(unsignedintn)//Nms延时函数 { unsignedinti=0; for(i=0;in;i++) Delay_1ms(); } voidwrite_data(unsignedchardata) { unsignedchari; SetLcdA0; ClrLcdCS; for(i=0;i8;i++) { if(data>=0x80) {SetLcdSdata;} else{ClrLcdSdata;} ClrLcdWR; asm("nop"); SetLcdWR; data=1; } SetLcdCS; } voidwrite_data16(unsignedchardata,unsignedchardataL) { unsignedchari; SetLcdA0; ClrLcdCS; for(i=0;i8;i++) { if(data>=0x80) {SetLcdSdata;} else{ClrLcdSdata;} ClrLcdWR; asm("nop"); SetLcdWR; data=1; } SetLcdCS; //Delay_nus(100); SetLcdA0; ClrLcdCS; for(i=0;i8;i++) { if(dataL>=0x80) {SetLcdSdata;} else{ClrLcdSdata;} ClrLcdWR; asm("nop"); SetLcdWR; dataL=1; } SetLcdCS; } voidwrite_cmd(unsignedchardata) { unsignedchari; ClrLcdA0; ClrLcdCS; for(i=0;i8;i++) { if(data>=0x80) {SetLcdSdata;} else{ClrLcdSdata;} ClrLcdWR; asm("nop"); SetLcdWR; data=1; } SetLcdCS; } // voidmain(void) {unsignedinti,j; init_devices(); Clrled; //insertyourfunctionalcodehere... Delay_nms(100); ClrLcdRST; Delay_nms(5); SetLcdRST; { Delay_nms(100); write_cmd(0x10); write_data16(0x2f,0x8e); write_cmd(0x11); write_data16(0x00,0x0c); write_cmd(0x07); write_data16(0x00,0x21); write_cmd(0x28); write_data16(0x00,0x06); write_cmd(0x28); write_data16(0x00,0x05); write_cmd(0x27); write_data16(0x05,0x7f); write_cmd(0x29); write_data16(0x89,0xa1); write_cmd(0x00); write_data16(0x00,0x01); Delay_nms(100); write_cmd(0x29); write_data16(0x80,0xb0); Delay_nms(30); write_cmd(0x29); write_data16(0xff,0xfe); write_cmd(0x07); write_data16(0x00,0x23); Delay_nms(30); write_cmd(0x07); write_data16(0x00,0x33); write_cmd(0x01); write_data16(0x21,0x83); write_cmd(0x2f); write_data16(0xff,0xff); write_cmd(0x2c); write_data16(0x80,0x00); write_cmd(0x03); write_data16(0x68,0x30);//6830 write_cmd(0x27); write_data16(0x05,0x70); write_cmd(0x02); write_data16(0x03,0x00); write_cmd(0x0b); write_data16(0x58,0x0c); write_cmd(0x12); write_data16(0x06,0x09); write_cmd(0x13); write_data16(0x31,0x00); write_cmd(0x2a); write_data16(0x1d,0xd0); write_cmd(0x2b); write_data16(0x0a,0x90); write_cmd(0x2d); write_data16(0x31,0x0f); Delay_nms(100); //write_cmd(0x10); //write_data16(0x2f,0x8e); //write_cmd(0x11); //write_data16(0x00,0x0c); write_cmd(0x45); write_data16(0x83,0x00); write_cmd(0x44); write_data16(0x83,0x00); write_cmd(0x21); write_data16(0x00,0x00); write_cmd(0x1e); write_data16(0x00,0xbf); Delay_nms(1); write_cmd(0x1e); write_data16(0x00,0x00); Delay_nms(100); write_cmd(0x45); write_data16(0x83,0x00); write_cmd(0x44); write_data16(0x83,0x00); write_cmd(0x21); write_data16(0x00,0x00); write_cmd(0x22);//writedatatoGRAM Setled; while(1) { write_cmd(0x45); write_data16(0x83,0x00); write_cmd(0x44); write_data16(0x83,0x00); write_cmd(0x21); write_data16(0x00,0x00); write_cmd(0x22);//writedatatoGRAM for(i=0;i17500;i++) {write_data(0xf8); write_data(0x00);} Delay_nms(5000); write_cmd(0x45); write_data16(0x83,0x00); write_cmd(0x44); write_data16(0x83,0x00); write_cmd(0x21); write_data16(0x00,0x00); write_cmd(0x22);//writedatatoGRAM for(i=0;i17500;i++) {write_data(0x07); write_data(0xe0);} Delay_nms(5000); write_cmd(0x45); write_data16(0x83,0x00); write_cmd(0x44); write_data16(0x83,0x00); write_cmd(0x21); write_data16(0x00,0x00); write_cmd(0x22);//writedatatoGRAM for(i=0;i17500;i++) {write_data(0x00); write_data(0x1f);} Delay_nms(5000); } } } ……
版权说明:本资料由用户提供并上传,仅用于学习交流;若内容存在侵权,请进行举报,或 联系我们 删除。
PARTNER CONTENT
相关评论 (下载后评价送E币 我要评论)
没有更多评论了
  • 可能感兴趣
  • 关注本资料的网友还下载了
  • 技术白皮书