dspic5011驱动金鹏 OLED12864-4,显示成功

2020-02-06 10:23发布

在51基础上改写的,单片机为DSPIC5011,花了半天时间,供学习DSPIC的人借鉴。

main.c
//oled========12864-4显示,  程序清单
//  1   VDD      2   GND  
//  3   /cs      4   Rst
//  5         d/c      6   r/w             
//  7   e/rd          8  D0/SCK      
//  9        D1/SDA   10 D2
// 11   D3       12 D4
// 13   D5       14 D6
// 15   D7       16 GND

/ /main.c
#include <p30f5011.h>                            //dsPIC30F5011标准头文件
#include "pic.h"
#include <libpic30.h>
//配置位
// _FOSC(CSW_FSCM_OFF & XT_PLL4);  //4倍频晶振,Failsafe 时钟关闭
  _FOSC(CSW_FSCM_OFF & FRC);                   //内部RC晶振,
  _FWDT(WDT_OFF);                    //关闭看门狗定时器
  _FBORPOR(PBOR_OFF & MCLR_EN);     //掉电复位禁止,MCLR复位使能。
  _FGS(CODE_PROT_OFF);              //代码保护禁止
#define uint  unsigned int                       
#define uchar unsigned char
#define u16  unsigned int                       
#define u8 unsigned char
// #define nop _nop_()   
//#define Fcy 7372800                  //7.37MHz外部晶振带4倍频,指令周期为7.37MIPs
/////////////////12864液晶端口定义////////////////////////
//#define     DATA_PORT          LATGB      //8 bit数据线
#define     RE                 LATGbits.LATG3     //片选信号
#define     RW                 LATGbits.LATG2     //读写控制
#define     RS                 LATCbits.LATC15    //数据/命令选择
#define     CS                 LATFbits.LATF6     //
#define     RST                LATFbits.LATF2     //

#define comm  0
#define dat   1
void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint us);
uchar rd_lcd (uchar dat_comm);


const  uchar  Char8x16[]={
/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,

/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,

/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,

/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,

/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,

/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
} ;         



//延时函数1---  x(ms)
void delay_ms(unsigned int n1)
{
unsigned int m,n;
for(m=0;m<80;m++)
for(n=0;n<n1;n++);
}

void delay (uint us)   //delay time
{
        while(us--);
}

void delay1 (uint ms)
{

unsigned int m,n;
for(m=0;m<100;m++)
for(n=0;n<ms;n++);
/*
        uint i,j;
        for(i=0;i<ms;i++)
        for(j=0;j<15;j++)
        delay(1);
*/
}
//=======写列地址==============
void Set_Colume_Address(unsigned char Data)
{
    unsigned char tmp;       
    tmp=0x0f&Data;
    wr_lcd(comm,tmp);       //送列地址低四位
   
        tmp=Data>>4;
    wr_lcd(comm,0x10|tmp);  //送列地址高四位

}

//=======写页地址==============
void Set_Page_Address(unsigned char page_addr)
{
        wr_lcd (comm,page_addr|0xb0);
}

//=======显示图形===============
void Display_Picture(const uchar  *pic)
{
        unsigned char i,j;
        for(i=0;i<8;i++)
        {
                Set_Page_Address(i);
                Set_Colume_Address(0x00);
                for(j=0;j<0x80;j++)
                {
                        wr_lcd (dat,*(pic+0x80*i+j));
                }
        }
}

/*------------------初始化-----------------*/
void init_lcd (void)
{   //BGCF
/*
#define     DATA_PORT              LATB           //8 bit数据线
#define     RE                 LATGbits.LATG3     //片选信号
#define     RW                 LATGbits.LATG2     //读写控制
#define     RS                 LATCbits.LATC15    //数据/命令选择
#define     CS                 LATFbits.LATF6      //左半屏
#define     RST                LATFbits.LATF2     //右半屏
*/   
    TRISB &=0X0000;
    TRISG &=0XFFF3;
    TRISC &=0X7FFF;
    TRISF &=0XFFBB;  // 1111111110111011
   
        CS=1;
        RE=1;
        RW=1;
        delay1(100);
        RST=0;
        delay1(1);
        RST=1;
        delay1(100);
        /*
        wr_lcd (comm,0xAE);        //Set Display Off

        wr_lcd (comm,0xD5); //Set Display Clock Divide Ratio/Oscillator Frequency
        wr_lcd (comm,0x80);
       
        wr_lcd (comm,0xA8); //Set Multiplex Ratio
        wr_lcd (comm,0x3F);
       
        wr_lcd (comm,0xD3);        //Set Display Offset
        wr_lcd (comm,0x00);
               
        wr_lcd (comm,0x40);        //Set Display Start Line
       
        wr_lcd (comm,0xA0);        //0xA1        Set Segment Re-Map

        wr_lcd (comm,0xC0);        //0xC8        Set COM Output Scan Direction
       
        wr_lcd (comm,0xDA);        //Set COM Pins Hardware Configuration
        wr_lcd (comm,0x12);
       
        wr_lcd (comm,0x81);        //Set Contrast Control
        wr_lcd (comm,0x7F);
       
        wr_lcd (comm,0xD9);        //Set Pre-Charge Period
        wr_lcd (comm,0xF1);
       
        wr_lcd (comm,0xDB);        //        Set VCOMH Deselect Level
        wr_lcd (comm,0x40);

        wr_lcd (comm,0xA4);        //Set Entire Display On/Off
       
        wr_lcd (comm,0xA6);        //Set Normal/Inverse Display
        //Clear Screen

        wr_lcd (comm,0x8D);        //        Set Charge Pump
        wr_lcd (comm,0x14);
       
        wr_lcd (comm,0xAF);        //        Set Display On
       
        //Power Stabilized (100ms Delay Recommended)
        //delay1(2);
        //wr_lcd (comm,0xa5);  //全显//
        //wr_lcd (comm,0xaf);  //开显示//

        wr_lcd (comm,0x20);  //Set Memory Addressing Mode //
        wr_lcd (comm,0x02);
        delay1(100);
        */
        wr_lcd (comm,0xFD); //Command Lock
        wr_lcd (comm,0x12);
       
        wr_lcd (comm,0xAE);        //Set Display Off

        wr_lcd (comm,0xD5); //Set Display Clock Divide Ratio/Oscillator Frequency
        wr_lcd (comm,0xa0);
       
        wr_lcd (comm,0xA8); //Set Multiplex Ratio
        wr_lcd (comm,0x3F);
       
        wr_lcd (comm,0xD3);        //Set Display Offset
        wr_lcd (comm,0x00);
               
        wr_lcd (comm,0x40);        //Set Display Start Line
       
        wr_lcd (comm,0xA0);        //0xA1 Set Segment Re-Map

        wr_lcd (comm,0xC0);        //0xC8        Set COM Output Scan Direction
       
        wr_lcd (comm,0xDA);        //Set COM Pins Hardware Configuration
        wr_lcd (comm,0x12);
       
        wr_lcd (comm,0x81);        //Set Contrast Control
        wr_lcd (comm,0x7F);
       
        wr_lcd (comm,0xD9);        //Set Pre-Charge Period
        wr_lcd (comm,0x25);
       
        wr_lcd (comm,0xDB);        //        Set VCOMH Deselect Level
        wr_lcd (comm,0x34);

        wr_lcd (comm,0xA4);        //Set Entire Display On/Off
       
        wr_lcd (comm,0xA6);        //Set Normal/Inverse Display
        //Clear Screen

//        wr_lcd (comm,0x8D);        //        Set Charge Pump
//        wr_lcd (comm,0x14);
       
        wr_lcd (comm,0xAF);        //        Set Display On
       
        //Power Stabilized (100ms Delay Recommended)

        wr_lcd (comm,0x20);  //Set Memory Addressing Mode //
        wr_lcd (comm,0x02);
        delay1(100);
}
/*---------------------------------------*/

void wr_lcd (uchar dat_comm,uchar content)
{   u16  data=0;

        // chk_busy ();
        CS=0;
        if(dat_comm)
        {
                RS=1;   //data
        }
        else
        {
                RS=0;   //command
        }
        RE=1;
        RW=0;   //write   
        data|=content;
    data<<=8;
        LATB =data;   //output data or comm
        //  delay(5);
        RW=1;
        CS=1;
        //delay(50);
}

/*
uchar rd_lcd (uchar dat_comm)
{
        uint rdata;
        // chk_busy ();
    TRISB|=0XFF00;
        if(dat_comm)
        {
                RS=1;   //data
        }
        else
        {
                RS=0;   //command
        }
        RW=1;   //write
        RE=0;  
        rdata=PORTB;   //output data or comm
        //  delay(5);
        RE=1;  
        rdata=rdata>>8;
    TRISB&=0X00FF;
        return rdata;
}
*/
/*显示点阵*/
void Display_Grid(uchar data1,uchar data2)
{
        uchar i,j;
        for(i=0;i<8;i++)
        {
                Set_Page_Address(i);
                Set_Colume_Address(0x00);
                for(j=0;j<64;j++)
                {
                        wr_lcd (dat,data1);
                        wr_lcd (dat,data2);
                }
        }
}
//在x0,y0处显示x_number*(8*y_number)图形.
//..........显示中文.............
void pho_disp( const uchar  *chn,uchar x0,uchar y0,uchar x_number,uchar y_number)
{
        uchar i,j;
        for(i=0;i<y_number;i++)
        {       
                Set_Page_Address(y0+i);
                Set_Colume_Address(x0);
                for(j=0;j<x_number;j++)
                {
                        wr_lcd (dat,*chn++);
                }
        }
}
void DispCharTest(void)
{
        uchar i,j;
        for(j=0;j<10;j++)
        {
                for(i=0;i<10;i++)
                {
                        pho_disp (Char8x16+16*j,i*8,0,8,2);  //在第0像素行(Y地址0X80),第0个字数字置显示“0”;每一行有16个数字位置
                }
                delay1 (100);
        }
}
/*------------------主程序--------------------*/
void main ()
{   TRISD&=0XFF7F;
    LATDbits.LATD7=1;
       
        init_lcd ();
        Display_Grid(0x00,0x00);
   
        while (1)
        {
                wr_lcd (comm,0xa6);
                delay1(10);
                Display_Picture(pic);
                delay1(1000);
       
                wr_lcd (comm,0xa6);
                Display_Picture(pic1);
                delay1(1000);
               
                wr_lcd (comm,0xa7);
                delay1(1000);
                wr_lcd (comm,0xa6);
                Display_Grid(0xff,0x00);
                delay1(1000);
                wr_lcd (comm,0xa7);
                delay1(1000);
                Display_Grid(0x55,0x55);
                delay1(1000);
                Display_Grid(0xaa,0xaa);
                delay1(1000);                
                wr_lcd (comm,0xa6);                  
                Display_Grid(0x00,0x00);
                DispCharTest();
               
        }
}          

//pic.h

unsigned  char code pic[]={
/*--  调入了一幅图像:C:Documents and SettingsAdministrator桌面12864-9.bmp  --*/
/*--  宽度x高度=128x64  --*/
0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x81,
0xC1,0xF1,0x3D,0x1D,0x29,0xC1,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xF1,0x21,0x21,0x21,0x21,0xF1,
0x21,0x01,0x01,0xF1,0xE1,0x21,0x21,0x21,0xF1,0xF1,0x21,0x01,0xE1,0xC1,0x41,0x41,
0x79,0x59,0x49,0x41,0xC1,0xE1,0x41,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x60,0x30,0x18,0x98,0x8E,0x87,0x83,
0x81,0x80,0x80,0x80,0x80,0x80,0x81,0x83,0x86,0x4C,0x6C,0x58,0x38,0x30,0x70,0x60,
0xE0,0xE0,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x10,0xFF,
0x00,0x00,0x00,0xFF,0xFF,0x10,0x10,0x10,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,
0x42,0x5E,0xCC,0xC0,0xFF,0x7F,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x10,0x10,0x50,0x90,0x90,0x10,0x10,0x10,
0x10,0x10,0xFF,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0xD0,0xD0,0x90,0x98,0x1C,0x18,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x08,0x08,0x08,0x08,0xFF,
0x00,0x00,0x00,0xFF,0x1F,0x08,0x08,0x08,0xFF,0xFF,0x80,0x80,0x87,0x8F,0x84,0x84,
0x84,0x84,0xC4,0xC4,0x84,0xFC,0xFE,0x04,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,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,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x23,0x2F,0x3E,0x24,
0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x30,0x2C,0x27,0x23,0x21,0x20,0x20,0x20,0x20,
0x30,0x38,0x30,0x20,0x00,0x00,0x00,0x40,0x30,0x0F,0x01,0x08,0x08,0x18,0x38,0x1F,
0x60,0x18,0x0F,0x03,0x00,0x10,0x10,0xF0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x10,0x30,0x70,0x70,0x3F,0x0F,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,
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,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xF8,0x10,0x10,0x10,
0x10,0x90,0x10,0x10,0x10,0x10,0x10,0x12,0x1E,0x9E,0x90,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x90,0xD0,0x70,0x38,0x30,0x20,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x02,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x10,0x30,
0xE0,0xE0,0xC3,0x07,0x0E,0x06,0x00,0x00,0x00,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x06,
0x3C,0xF8,0xF0,0xC0,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0xC0,0xE0,0x3C,0x1F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0xFF,
0xFF,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
0x04,0x05,0x04,0x04,0x04,0x84,0xE4,0x74,0x3F,0x2F,0x25,0x24,0x44,0x44,0xC4,0x84,
0x84,0x84,0x02,0x02,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0x0F,0x07,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x08,0x04,0x03,0x01,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,0x90,0x88,0x88,0x88,0x84,0x84,
0x84,0x82,0x82,0x83,0x81,0x81,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x81,
0x81,0x83,0x87,0x8F,0x8E,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x82,0x82,0x82,0x82,
0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x83,0x83,0x82,0x82,0x82,0x82,0x82,0x82,0x83,
0x83,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x83,0x83,0x83,0x82,0x80,0x80,0x80,0xFF,

};
unsigned char code pic1[]={
0xFF,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x81,0xC1,0x41,0x01,0x81,0x81,0xC1,0x81,0x81,0x81,0x81,0xC1,0xE1,
0x01,0x01,0x01,0x01,0x01,0x81,0x81,0xC1,0x61,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x81,0x81,0x81,0x81,0xC1,0xC1,0xC1,0xE1,0xE1,0xE1,0xE1,
0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xC1,0xC1,0xC1,0xC1,0x81,0x81,0x81,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0xFF,
0xFF,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,0x00,0x00,0x00,0xC0,0xE0,0xFF,
0xFE,0xFC,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x3F,0x3E,0x3E,
0x1E,0x1E,0x0E,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xF8,
0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,0xFB,0xBB,0xBB,0xB9,0xB9,
0xB9,0xB9,0x39,0x39,0x39,0x39,0x71,0x71,0x71,0xE3,0xE3,0xC3,0xC7,0x87,0x07,0x0F,
0x1F,0x1E,0x7C,0xF8,0xE0,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,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFD,0xFC,0xFE,
0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFC,0xFC,0xF0,0xE0,0x81,0x03,0x07,0x1F,0xFE,
0xF8,0x00,0x00,0x00,0xFF,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,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
0xFC,0xF8,0xF8,0xF8,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x9F,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x7F,0xFF,0x7F,0x00,0x00,0x03,0x01,
0x00,0x00,0x04,0x02,0x01,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,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x3F,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x7F,0x1E,0x01,0x87,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x0F,
0x00,0x03,0xFF,0x7F,0x3F,0x0F,0x07,0x01,0x00,0xFC,0x03,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,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,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x3F,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x1F,
0x1F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,0x7F,0x07,0x03,0x0F,0x10,
0x00,0x00,0x1C,0x0F,0x07,0x07,0x03,0x00,0x0E,0x07,0x07,0x03,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,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,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x10,0x3F,0x0F,0x03,0x80,0x80,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x21,0x91,0x51,0x33,0x3F,0x1F,0x34,0x64,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,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,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x88,0x88,0x88,0x88,
0x88,0x98,0x8C,0x84,0x86,0x82,0x89,0x80,0x80,0x87,0x80,0x80,0x82,0x80,0x80,0x84,
0x80,0x80,0x80,0x80,0x80,0x81,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xFF,
};
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
dazelong2018
1楼-- · 2020-02-06 15:41
[img]D:Backup桌面OCMO12864-2或-3[/IMG_20141124_205411]
dazelong2018
2楼-- · 2020-02-06 18:32
OLED12864-4显示图片
dazelong2018
3楼-- · 2020-02-06 21:32
附件OCMO12864-2或-3(51程序)
dazelong2018
4楼-- · 2020-02-06 22:20
OCMO12864-2或-3(51程序)
卡斯发动机
5楼-- · 2020-02-06 22:54
 精彩回答 2  元偷偷看……
dazelong2018
6楼-- · 2020-02-07 00:16
如6楼所说,改成定时器延时程序如下:
void timer1_init(void)
{
        T1CON = 0;              //确保T1关闭,再进行初始化
        IFS0bits.T1IF = 0;     //清T1复位标志,使T1复位   
        IPC0bits.T1IP = 5;     //3个BIT,设置T1的中断优先级,0~7,7是做高优先级      
        IEC0bits.T1IE = 1;     //开T1中断
        T1CONbits.TCKPS = 3;   //设置T1的预分频比是8,即T1加一次需要的时间为1/(32M/8)秒,即0.25uS
                                          //2个bit,00--1:1,01--1:8,10--1:64,11--1:256
      
        PR1=(Fcy/256/4/2000);     //  1ms
      //  T1CONbits.TON = 1;     //打开T1并开始计数

}


void delay1 (uint ms)
{
  
time_counter=ms;
T1CONbits.TON = 1;
while(time_counter!=0);
time_counter=0;
T1CONbits.TON = 0;

}

//====================定时中断服务程序======================
void __attribute__((__interrupt__,no_auto_psv)) _T1Interrupt(void)
{       //PR1=40320/Ftimer1;   //计算定时器的溢出值   
        //          PR1=(Fcy/256/4/200);     //  10ms
        IFS0bits.T1IF = 0;     //在软件里清中断标志
               
            if(time_counter!=0)
                {  time_counter--;
                   //led1=!led1; led=!led;  // LATCbits.LATC13 = !LATCbits.LATC13;   
                    LATDbits.LATD7 = !LATDbits.LATD7;       // LED1闪亮          
                }                  
}  

一周热门 更多>