本帖最后由 xuwei 于 2015-6-14 01:23 编辑
做摄像头快一个半月了,今天终于有了重大的进展,终于把图像搞出来了,可是图像是发白,模糊,我初步估计是数据lost ,所以还要继续努力!
加油吧
江苏无锡市第五项目部临时工棚
主程序
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- /*记住自己做完头文件别忘了在左上角的品字形图标的C/C++里设置一下include选项奥,负责要出错的*/
- GPIO_InitTypeDef GPIO_InitStructure;
-
- int main(void)
- {
-
- uint32_t numb;
- uint16_t date1,date2;
- init_STM32(); //开机初始化
-
- // my_send_byte(0x00); //发送一个字节
- //my_send_byte(0x01); //发送一个字节
- //my_send_byte(0x02); //发送一个字节
- //my_send_byte(0x03); //发送一个字节
- CLK_init_ON();//开启PA8的输出时钟8MHZ
- LCD9328_init();//9328初始化
- SCCB_IIC_INIT();//IIC初始化函数
-
- delay1ms(20);
- init_OV7670_POWER_UP();//0V7670的初始化寄存器设置
- delay1ms(10);
- // wrOV7670Reg(0x40, 0xd0);
- write_ov7670_sccb_twi(0x17, 0x16);
- write_ov7670_sccb_twi(0x18, 0x04);
- write_ov7670_sccb_twi(0x19, 0x02);
- write_ov7670_sccb_twi(0x1A, 0x7B);
- write_ov7670_sccb_twi(0x32, 0x40);
- write_ov7670_sccb_twi(0x03, 0x0a);
- // wrOV7670Reg(0x3E, 0x1A);
-
- write_ov7670_sccb_twi(0x70, 0x3A);
- write_ov7670_sccb_twi(0x71, 0x35);
- write_ov7670_sccb_twi(0x72, 0x11);
- write_ov7670_sccb_twi(0x73, 0xF9);
- write_ov7670_sccb_twi(0xA2, 0x02);
- delay1ms(10);
-
-
- CLR_CS;
- CLR_RS;
- SET_RD;
- CLR_WR;
- GPIOE->ODR=0x0022;//GPIO_Write(GPIOE, reg);// //写入命令
- SET_WR;
- SET_RS;
-
- SET_FIFO_WE;
- CLR_FIFO_WRST; //复位写地址为0
- delay1us(40);
- SET_FIFO_WRST;//初始化完毕,将从0地址开始
- CLR_FIFO_WE;//关闭写FIFO使能
- CLR_FIFO_CS;//使能读
- CLR_FIFO_RD; //RCK时钟拉低
- CLR_FIFO_RRST; //度地址复位
- SET_FIFO_RD;//RCK拉高
- CLR_FIFO_RD; //RCK拉低
- SET_FIFO_RD; //RCK拉高
- CLR_FIFO_RD;
- SET_FIFO_RD; //RCK拉高
- CLR_FIFO_RD;
- CLR_FIFO_RD;
- SET_FIFO_RD; //RCK拉
- delay1us(2);
- SET_FIFO_RRST; //拉高复位结束
-
- //SET_FIFO_CS;//关闭能读
- // SET_FIFO_WE;//开启写FIFO使能
-
- my_EXTI_int();//外部中断初始化
- while(1)
- {
- if(vsync_counter==2)
- {
- EXTI->IMR=0;
- NVIC->ISER[0]=0;
- for(numb=76800;numb;numb--)
- {
- CLR_FIFO_RD;
- SET_FIFO_RD;
- date1=GPIOA->IDR;
- date1<<=8;
- CLR_FIFO_RD;
- SET_FIFO_RD;
- date2=GPIOA->IDR;
-
- GPIOE->ODR=((date1&0xff00)|(date2&0x00ff));
- CLR_WR;
- SET_WR;
-
-
- }
-
-
-
- CLR_FIFO_RRST; //读指针复位
- CLR_FIFO_RD;
- SET_FIFO_RD;
- CLR_FIFO_RD;
- SET_FIFO_RD;
- SET_FIFO_RRST;
- CLR_FIFO_WRST;
- delay1us(2);
- SET_FIFO_WRST;
- vsync_counter = 0;
- EXTI->IMR=0x00000001;
- NVIC->ISER[0]=0x00000040;
-
- }
- }
-
-
- }
- void init_STM32()
- {
- delay1ms(10000);
- mysysinit();
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//使能GPIOA时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能GPIOB时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能GPIOC时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);//使能GPIOD时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);//使能GPIOE时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//使能AFIO复用时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能USART1时钟
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); //使能IIC1时钟
- /* LED8-11设置为指示灯,设置为输出推挽 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9|GPIO_Pin_10 | GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- /* 设置IIC总线的 PB10 and PB11 in 开楼复用输出 mode */ //I2C的两条总线
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* 设置PD口用于控制LCD的控制总线 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- /* 设置PE口用于控制LCD的为输出 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3| GPIO_Pin_4|
- GPIO_Pin_5 | GPIO_Pin_6| GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9|
- GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14|
- GPIO_Pin_15 ;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- /* 设置PA口的低8位用于控制7670的数据输出 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3| GPIO_Pin_4|
- GPIO_Pin_5 | GPIO_Pin_6| GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* 422B的操作设置,设置为输出推挽 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14|GPIO_Pin_13 | GPIO_Pin_12| GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /*串口初始化*/
- //my_USART_init();
-
- }
-
- void mysysinit()//系统初始化程序
- {
- ErrorStatus HSEStartUpStatus;//说明标志位
- RCC_DeInit();//所有外设全部缺省设置
- /* Enable HSE */
- RCC_HSEConfig(RCC_HSE_ON);
- /* Wait till HSE is ready and if Time out is reached exit */
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)//启动成功
- {
- /*这两条FLASH指令必须加上,不知为啥?不加上就运行几秒后出错,参照系统初始化*/
- /* Enable The Prefetch Buffer */
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//FLASH缓存开启
- /* Configure the Latency cycle: Set 2 Latency cycles */
- FLASH_SetLatency(FLASH_Latency_2); //设置FLASH这些位表示SYSCLK(系统时钟)周期与闪存访问时间的比例,为010:两个等待状态,当 48MHz < SYSCLK ≤ 72MHz
- /* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//外部时钟为8M,PLL的输入时钟=8MHZ,倍频系数9,
- /* Configure HCLK such as HCLK = SYSCLK */
- RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置了啦AHB分频器的分频系数=1,即HCLK=SYSCLK=72MHZ
- /* Configure PCLK1 such as PCLK1 = HCLK/2 */
- RCC_PCLK1Config(RCC_HCLK_Div2);//设置了APB1外设的时钟频率最大是36M这里是APB1的分频器设为2,PCLK1=HCLK/2=72/2=36MHZ正好是最大值
- /* Configure PCLK2 such as PCLK2 = HCLK */
- RCC_PCLK2Config(RCC_HCLK_Div1);//设置PLCK2=HCLK=72MHZ,的APB2分频器=1
- /* Select the PLL as system clock source */
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//设置了SYSCLK的提供者为PLL,频率由上面算出=72MHZ
- /* disable PLL Ready interrupt */
- RCC_ITConfig(RCC_IT_PLLRDY, DISABLE);//PLL中断关闭
- /* disable PLL Ready interrupt */
- RCC_ITConfig(RCC_IT_HSERDY,DISABLE);//HSE中断关闭
- /* disable PLL Ready interrupt */
- RCC_ITConfig(RCC_IT_HSIRDY, DISABLE); //HSI中断关闭
- /* disable PLL Ready interrupt */
- RCC_ITConfig(RCC_IT_LSERDY, DISABLE); //LSE中断关闭
- /* disable PLL Ready interrupt */
- RCC_ITConfig(RCC_IT_LSIRDY, DISABLE); //LSI中断关闭
- /* PLL clock divided by 1.5 used as USB clock source */
- RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);//设置USB的时钟为=72、1.5=48mhz
- /* Configure ADCCLK such as ADCCLK = PCLK2/2 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div2);//设置ADC时钟=PCLK2/2= 36MHZ
- /* disable the LSE */
- RCC_LSEConfig(RCC_LSE_OFF);//外部低速晶振关闭
- /*DISable the RTC clock */
- RCC_RTCCLKCmd(DISABLE);
- /* DISable the Clock Security System */
- RCC_ClockSecuritySystemCmd(DISABLE);
- /* Enable the PLL */
- RCC_PLLCmd(ENABLE);//使能PLL
-
-
-
- /* PLL ans system clock config */
- }
- else
- {
- /* Add here some code to deal with this error */
- }
-
-
- }
- 中断程序
- #include "stm32f10x_it.h"
- uint8_t vsync_counter=0;
- void EXTI0_IRQHandler(void)//场中断 PC0
- { EXTI->PR|=0x00000001;
- // EXTI->IMR=0;
- vsync_counter++;
- if(2==vsync_counter)
- {
- CLR_FIFO_CS;//使能读
- CLR_FIFO_WE;//禁止写入FIFO数据
-
-
-
-
- }
- else
- {SET_FIFO_WE;//开启写FIFO使能
- }
- //EXTI->IMR=0x00000001;
- }
- 7670程序
- void init_OV7670_POWER_UP()//0V7670的初始化寄存器设置
- {
- uint16_t i;
- for(i=0;i<176;i++)
- {
- write_ov7670_sccb_twi(change_reg[i][0],change_reg[i][1]);
-
- }
- /*PA8的MCO时钟输出为关闭,切换到普通IO*/
- void CLK_init_OFF(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- //时钟的输出txz
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- RCC->CFGR&=0xf8ffffff;//RCC_MCOConfig(RCC_MCO_HSE );//hsi
- }
- void write_ov7670_sccb_twi(uint8_t add,uint8_t date)
- { uint8_t a;
- delay1ms(500);
- I2C1->CR1=1;//开启IIC
- //my_send_byte(0x80);
- I2C1->CR1=0x0101;//发送起始位
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0001);
- delay1ms(1);
- //my_send_byte(0x11);
- if(a==0x0001)
- break;
-
-
- }//EV5是向下
- I2C1->DR=0x42;//写入地址
- delay1ms(10);
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0002);
- delay1ms(1);
- // my_send_byte(0x22);
- if(a==0x0002)
- break;
-
-
- }//EV6ADDR发送?是向下,否等待
- a=I2C1->SR1;
- a=I2C1->SR2;
- //my_send_byte((I2C1->SR1));
- //my_send_byte((I2C1->SR2)); //必须读SR1
-
- I2C1->DR=add;//写入寄存地址
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0080);
- delay1ms(1);
- //my_send_byte(0x33);
- if(a==0x0080)
- break;
-
-
- }//EV8寄存器为空?是向下,否等待
- a=I2C1->SR1;
- a=I2C1->SR2;
- //my_send_byte((I2C1->SR1));
- //my_send_byte((I2C1->SR2)); //必须读SR1
-
- I2C1->DR=date;//写数据
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0080);
- delay1ms(1);
- // my_send_byte(0x44);
- if(a==0x0080)
- break;
-
-
- }//EV8寄存器为空?是向下,否等待
- delay1ms(1);
- while(1)
- {a=I2C1->SR1;
- a=(a&0x0084);
- delay1ms(1);
- // my_send_byte(0x55);
- if(a==0x0084)
- break;
-
-
- }//EV8-2发送完成,寄存器为空?是向下,否等待
-
-
-
-
- I2C1->CR1=0x0201;//STOP
-
- }
- /******************************
- SCCB底层操作函数利用硬件模块IIC读取一个指定地址的数据
- 返回值:为读取的数据
- 形参:为将要读取的寄存器地址
- *****************************8*/
- uint8_t SCCB_IIC_READ(uint8_t add)//读一个字节数据
- {
- uint8_t date;
- uint16_t a;
- delay1ms(3000);
- I2C1->CR1=1;//开启IIC
- //my_send_byte(0x80);
- I2C1->CR1=0x0101;//发送起始位
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0001);
- delay1ms(2);
- // my_send_byte(0x11);
- if(a==0x0001)
- break;
-
-
- }//EV5是向下
- I2C1->DR=0x42;//写入地址
-
- delay1ms(10);
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0002);
- delay1ms(1);
- // my_send_byte(0x22);
- if(a==0x0002)
- break;
-
-
- }//EV6ADDR发送?是向下,否等待
- a=I2C1->SR1;
- a=I2C1->SR2;
- //my_send_byte((I2C1->SR1));
- //my_send_byte((I2C1->SR2)); //必须读SR1
-
- I2C1->DR=add;//写入寄存地址
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0080);
- delay1ms(1);
- // my_send_byte(0x33);
- if(a==0x0080)
- break;
-
-
- }//EV8寄存器为空?是向下,否等待
-
- delay1ms(1);
- while(1)
- {a=I2C1->SR1;
- a=(a&0x0084);
- delay1ms(1);
- // my_send_byte(0x44);
- if(a==0x0084)
- break;
-
-
- }//EV8-2发送完成,寄存器为空?是向下,否等待
-
-
-
-
- I2C1->CR1=0x0201;//STOP
- //delay(1000000);
- ///delay(10000);
- delay1ms(10);
- //my_send_byte(0x88);
- I2C1->CR1=0x0101;//发送起始位
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0001);
- delay1ms(2);
- //my_send_byte(0x55);
- if(a==0x0001)
- break;
-
-
- }//EV5是向下
- I2C1->DR=0x43;//写入地址
-
- delay1ms(1);
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0002);
- delay1ms(1);
- // my_send_byte(0x66);
- if(a==0x0002)
- break;
-
-
- }//EV6ADDR发送?是向下,否等待
- a=I2C1->SR1;
- a=I2C1->SR2;
- delay1ms(1);
- // my_send_byte(I2C1->SR1);
- // my_send_byte(I2C1->SR2);
-
- while(1)
- { a=I2C1->SR1;
- a=(a&0x0040);
- delay1ms(1);
- //my_send_byte(0x77);
- if(a==0x0040)
- break;
-
-
- }//EV7ARXEN发送?是向下,否等待
- date=I2C1->DR;
- I2C1->CR1=0x0201;//STOP
- return date;
- }
- void SCCB_IIC_INIT()//IIC初始化函数
- {
- delay1ms(5000);
- I2C1->CR1=0;//关闭I2C
- I2C1->CR2=2;//IIC的时钟源设为8MHZ,但是这不是总线上的时钟,他是由CCR1,分频后作为SCL时钟 的,见手册,
- I2C1->CCR=400;//标准IIC模式,对IIC时钟源的分频系数是40,用来产生10KHZ的SCL时钟
- I2C1->TRISE=3;//SCL的上升沿时间宽度为300NS
- I2C1->CR1=1;//开启IIC;
- }
- void delay1ms(uint32_t a)
- {
- for(a=23980;a;a--);
- }
- 9328程序
- #include "ili9328.h"
- uint8_t tab[]={/*-- 文字: 王 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,
- 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00};
- void write_LCD_CHINA_WRODS()
- {
- uint8_t i,val,n;
-
- wr_cmd_date(0x0050,0);//行开始坐标
- wr_cmd_date(0x0051,15); //行结束坐标
- wr_cmd_date(0x0052,0);//场开始地址坐标
- wr_cmd_date(0x0053,15); //场结束地址坐标
- wr_cmd_date(0x0020,0); //行地址计数器
- wr_cmd_date(0x0021,0);//场地址计数器
-
- for(n=0;n<32;n++)
- {
- for(i=0;i<8;i++)
- {
- val=tab[n];
- if(((val<<i)&0x80)==0x80)
- {
- wr_cmd_date(0x22,0x0000 );//bloke
- }
- else
- {
-
- wr_cmd_date(0x22,0xf800 );//red
-
- }
-
-
-
- }
-
-
- }
-
-
- }
- void lcm_coordinate(uint16_t x1,uint16_t y1 )//扫描地 写一个像素
- {
- wr_cmd_date(0x0050,x1);//行开始坐标
- wr_cmd_date(0x0051,x1); //行结束坐标
- wr_cmd_date(0x0052,y1);//场开始地址坐标
- wr_cmd_date(0x0053,y1); //场结束地址坐标
- wr_cmd_date(0x0020,x1); //行地址计数器
- wr_cmd_date(0x0021,y1);//场地址计数器
-
- }
- void LCD9328_init()//横屏初始
- {
- uint32_t a;
- delay1us(150000);
- wr_cmd_date(0x0001,0x0100); //s1-s720
- wr_cmd_date(0x0002,0x0700);
- wr_cmd_date(0x0003,0x1038);//默认0x1030,现在设为0X1038.1018
- wr_cmd_date(0x0004,0x0000);
- wr_cmd_date(0x0008,0x0404);
- wr_cmd_date(0x0009,0x0000);
- wr_cmd_date(0x000A,0x0000);
- wr_cmd_date(0x000C,0x0000);
- wr_cmd_date(0x000D,0x0000);
- wr_cmd_date(0x000F,0x0000);
- //power on sequence VGHVGL
- wr_cmd_date(0x0010,0x0080);
- wr_cmd_date(0x0011,0x0007);
- wr_cmd_date(0x0012,0x0000);
- wr_cmd_date(0x0013,0x0000);
- //vgh
- wr_cmd_date(0x0010,0x1590);
- wr_cmd_date(0x0011,0x0227);
- delay1us(800000);
- //vregiout
- wr_cmd_date(0x0012,0x001F); //0x001b
- delay1us(800000);
- //vom amplitude
- wr_cmd_date(0x0013,0x1500);
- delay1us(800000);
- //vom H
- wr_cmd_date(0x0029,0x0022);
- wr_cmd_date(0x002B,0x000F);
- //gamma
- wr_cmd_date(0x0030,0x0004);
- wr_cmd_date(0x0031,0x0307);
- wr_cmd_date(0x0032,0x0002);// 0006
- wr_cmd_date(0x0035,0x0206);
- wr_cmd_date(0x0036,0x0408);
- wr_cmd_date(0x0037,0x0507);
- wr_cmd_date(0x0038,0x0204);//0200
- wr_cmd_date(0x0039,0x0707);
- wr_cmd_date(0x003C,0x0405);// 0504
- wr_cmd_date(0x003D,0x0F02);
- //ram
- /*wr_cmd_date(0x0050,0x0000);
- wr_cmd_date(0x0051,0x00B0);
- wr_cmd_date(0x0052,0x0000);
- wr_cmd_date(0x0053,0x00DC);*/
- wr_cmd_date(0x0050,0x0000);
- wr_cmd_date(0x0051,0x00EF);
- wr_cmd_date(0x0052,0x0000);
- wr_cmd_date(0x0053,0x0013F);
- wr_cmd_date(0x0060,0xA700);
- wr_cmd_date(0x0061,0x0001);
- wr_cmd_date(0x006A,0x0000);
- //
- wr_cmd_date(0x0080,0x0000);
- wr_cmd_date(0x0081,0x0000);
- wr_cmd_date(0x0082,0x0000);
- wr_cmd_date(0x0083,0x0000);
- wr_cmd_date(0x0084,0x0000);
- wr_cmd_date(0x0085,0x0000);
- //
- wr_cmd_date(0x0090,0x0010);
- wr_cmd_date(0x0093,0x0003);
- wr_cmd_date(0x0095,0x0110);
- wr_cmd_date(0x0097,0x0000);
- wr_cmd_date(0x0098,0x0000);
- wr_cmd_date(0x0007,0x0173);
- for(a=76800;a;a--)
- {
- wr_cmd_date(0x22,0xF800);//红色刷屏
- }
- }
- void wr_cmd_date(uint16_t reg,uint16_t date)
- {
- GPIOE->CRL=0x33333333; //数据口转换成输出
- GPIOE->CRH=0x33333333; //数据口转换成输出
- CLR_CS;
- CLR_RS;
- SET_RD;
- CLR_WR;
- GPIOE->ODR=reg;//GPIO_Write(GPIOE, reg);// //写入命令
- SET_WR;
- SET_RS;
- //delay_1us(1);
- CLR_WR;
- GPIOE->ODR=date;//GPIO_Write(GPIOE, date); // //写入命令
- SET_WR;
- SET_CS;
- }
- uint16_t read_LCD_register(uint16_t reg)
- {
- uint16_t date;
- GPIOE->CRL=0x33333333; //数据口转换成输出
- GPIOE->CRH=0x33333333; //数据口转换成输出
- CLR_CS;
- //delay_1us(1);
- CLR_RS;
- //delay_1us(1);
- SET_RD;
- CLR_WR;
- GPIO_Write(GPIOE, reg); //写入命令
- SET_WR;
- //delay_1us(1);
- CLR_RD;
- GPIOE->CRL=0x88888888; //数据口转换成输入
- GPIOE->CRH=0x88888888; //数据口转换成输入
- // for(n=200;n;n--);
- date=(GPIOE->IDR);//读出数据
- SET_RD;
- SET_CS;
-
- return (date);
- }
- void delay1us(uint32_t time)
- { uint32_t b,c;
- for(c=time;c;c--) //定时=time*3*333.6=time*1000.8ns
- {
- for(b=8;b;b--); //8*13.9*3= 333.6
- }
-
- }
- 终端配置
- #include "EXTI.h"
- /***********************
- 外部中断初始化
- **************************/
- void my_EXTI_int()
- {
- /* PC0 被我设置成输入模式,上拉、下拉 */
- GPIOC->CRL=0x00000008;
-
- /*配置PC0作为中断输入线*/
- AFIO->EXTICR[0]=2;
- /*设置开启外部中断线0中断请求,其他的都关闭*/
- EXTI->IMR=0x00000001;
- /*PC0开启上升沿触发*/
- EXTI->RTSR=0x00000001;
- /*设置PC0中断的优先级为5*/
- NVIC->IP[6]=5;//VSYNC
- /*开启号中断即EXTI0,关闭其他所有外部的中断*/
- NVIC->ISER[0]=0x00000040; //开启PC0中断EXTI0 VSYNC中断
-
-
- }
-
复制代码
|