컨텐츠 바로가기


board


현재 위치

  1. 게시판
  2. 기타Q&A

기타Q&A

기타 문의 게시판입니다.

메일 확인부탁드립니다.
제목 메일 확인부탁드립니다.
작성자 강동훈 (ip:)
  • 작성일 2016-12-02 08:04:56
  • 추천 추천 하기
  • 조회수 795
  • 평점 0점

 

 메일로  LCD12864와 STM32 Cortex-M3 모듈 시리즈 문의 내용을 보내두었습니다.

---------메일 내용입니다.---------------------------

제가 현제 LCD12864와 STM32 Cortex-M3 모듈 시리즈를 구매하였습니다.

그리고 JK전자에서 지원하는 소스를 가지고 필요한 부분만 사용하여 프로그램을 작성하였습니다.

-------manyhead.h


#include "stm32f10x.h"

#include "stm32f10x_gpio.h"

#include "stm32f10x_rcc.h"

#include "stm32f10x_exti.h"

#include "stm32f10x_tim.h"

#include "stm32f10x_usart.h"


#include "misc.h"

#include "delay.h"


---------main.c


#include "manyhead.h" 


int main(){


    while(1) 

    {

bsp_lcd12864_init();


     LCD12864_Char_Set(0,0, "JK Electronics");

     LCD12864_Char_Set(1,0, "LCD12864 Test.");

     LCD12864_Char_Set(2,0, "www.jkelec.co.kr");

     LCD12864_Char_Set(3,0, "Date:2012.09.05");

    }

}


---------lcd12864.c

#include "lcd12864.h"
//#include "stm32f10x.h"

void LCD_Init0(void)
{
u8 cmd;
cmd=0x30;   // function set 8-bit data, the basic instructions
W_1byte(0,0,cmd); // write command
delay_ms(2);
cmd=0x0C;   // display status ON, cursor OFF, highlight OFF
W_1byte(0,0,cmd); 
delay_ms(2);
cmd=0x01;   // clear display
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x02;   // address of homing
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x80;   // Set DDRAM address
W_1byte(0,0,cmd);
delay_ms(2);
// Char_Set_XY(0,1,"LCD initializing");
// Char_Set_XY(0,2,"Please wait a moment.");
delay_ms(200);
//delay_ms(2500); 
}

void LCD_Init1(void)
{
u8 cmd;
cmd=0x30;   //  function set 8-bit data, the basic instructions
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x0C;   // display status ON, cursor OFF, highlight OFF
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x01;   // clear display
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x02;   // address of homing
W_1byte(0,0,cmd);
delay_ms(2);
cmd=0x80;   // Set DDRAM address
W_1byte(0,0,cmd);
delay_ms(2);
}

void W_1byte(u8 RW, u8 RS, u8 W_data)
{
u16 H_data,L_data,S_ID = 0xf8;  //11111RWRS0

if(RW == 0)
{
S_ID &=~ 0x04;
}
else     //if(RW==1)
{
S_ID |= 0X04;
}
if(RS == 0)
{
S_ID &=~ 0x02;
}
else     //if(RS==1)
{
S_ID |= 0X02;
}
H_data = W_data;
H_data &= 0xf0;   // lower 4 bits of data mask
L_data = W_data;     // xxxx0000 format
L_data &= 0x0f;   // 4 bits of data mask
L_data <<= 4;   // xxxx0000 format
Set_CS();
Write_8bits(S_ID);   // send S_ID
Write_8bits(H_data); // send H_data
Write_8bits(L_data); // send L_data
Clr_CS(); 
}

void Write_8bits(u16 W_bits)
{
u16 i,Temp_data;
for(i=0; i<8; i++)
{
Temp_data = W_bits;
Temp_data <<= i;
if((Temp_data&0x80)==0)
{
Clr_SID();
}
else
{
Set_SID();
delay_us(1);
Set_SCLK();
delay_us(1);
delay_us(1);
Clr_SCLK();
delay_us(1);
Clr_SID();
}
}




void LCD12864_Char_Set(u8 y, u8 x, u8 *p) 
if(y == 0)
{
W_1byte(0,0,(0x80+x)); 
}
if(y == 1)
{
W_1byte(0,0,(0x90+x));
}
if(y == 2)
{
W_1byte(0,0,(0x88+x));
}
if(y == 3)
{
W_1byte(0,0,(0x98+x));
}
while(*p != 0)
{
W_1byte(0,1,*p++);
}
}


void Set_Draw(void)
{
W_1byte(0,0,0x01);   // clear the screen
delay_ms(20);
W_1byte(0,0,0x34);   // 8BIT control interface, expanded instruction set, graphics OFF
delay_ms(20);
}


void Draw_Pic(u8 x, u8 y, const u8 *Draw)
{
u8 i, j, temp_x, temp_y;
temp_x = x;
temp_y = y;
temp_x |= 0x80;
temp_y |= 0x80;
for(i=0;i<32;i++ )
{
W_1byte(0,0,temp_y++);  // set the drawing area of ??the Y address coordinates
W_1byte(0,0,temp_x);  // set the drawing area coordinates of the X address
for(j=0;j<16;j++)
{
W_1byte(0,1,*Draw);
Draw++;
}
}

temp_x = 0x88;
temp_y = 0x80;
j = 0;

for(;i<64;i++ )
{
W_1byte(0,0,temp_y++);  // set the drawing area of ??the Y address coordinates
W_1byte(0,0,temp_x);   // set the drawing area coordinates of the X address
for(j=0;j<16;j++)
{
W_1byte(0,1,*Draw);
Draw++;
}
}
 
}


void Lcd_flash(u16 delay_ms_t, u8 times)
{
u8 j;
for(j=0;j<times;j++)
{
W_1byte(0,0,0x08);  // turn off the display
delay_ms(delay_ms_t);
W_1byte(0,0,0x0c);  // open display
delay_ms(delay_ms_t);
}
}

 
void Move(u8 step,u8 dirction,u16 time)
{
u8 i;
for(i=0;i<step;i++)       // move steps
{
 W_1byte(0,0,dirction);      // Text direction of movement
 delay_ms(time);             // move time control
}
}


void LCD12864_GPIO_OUTPUT(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC| RCC_APB2Periph_AFIO, ENABLE);
  GPIO_InitStructure.GPIO_Pin = 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_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

void LCD12864_GPIO_INPUT(void)
{

  GPIO_InitTypeDef GPIO_InitStructure;

  // Enable GPIOB clock
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
  GPIO_InitStructure.GPIO_Pin = 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_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

}

void bsp_lcd12864_gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

// LCD EN
GPIO_InitStructure.GPIO_Pin = LCD12864_EN_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD12864_EN_PORT, &GPIO_InitStructure);

// LCD RW
GPIO_InitStructure.GPIO_Pin = LCD12864_RW_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD12864_RW_PORT, &GPIO_InitStructure);

// LCD RS
GPIO_InitStructure.GPIO_Pin = LCD12864_RS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD12864_RS_PORT, &GPIO_InitStructure);

// LCD PSB
GPIO_InitStructure.GPIO_Pin = LCD12864_PSB_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD12864_PSB_PORT, &GPIO_InitStructure);


LCD12864_PSB_LOW();

LCD12864_GPIO_OUTPUT();

 }

void bsp_lcd12864_init(void)
{
bsp_lcd12864_gpio_init();

//LCD12864_DDR |= _BV(LCD12864_PSB_PIN_NO);
//LCD12864_PORT &= ~(_BV(LCD12864_PSB_PIN_NO));
Clr_CS();
Clr_SID();
Clr_SCLK();
//W_1byte(0,0,0x01);   // clear the screen
LCD_Init0();
delay_ms(1000);
LCD_Init1();  // key, otherwise the LCD power-on re-starting will not be displayed
//delay_ms(2000);
}

---------lcd12864.h

#ifndef __LCD12864_H
#define __LCD12864_H

#include "manyhead.h"

// ST7920 LCD driver 12864 driver, 3-wire serial mode


#define LCD12864_EN_PORT   GPIOC
#define LCD12864_EN_PIN  GPIO_Pin_3
#define LCD12864_EN_HIGH()      GPIO_SetBits(LCD12864_EN_PORT, LCD12864_EN_PIN)  
#define LCD12864_EN_LOW()      GPIO_ResetBits(LCD12864_EN_PORT, LCD12864_EN_PIN)  

#define LCD12864_RW_PORT   GPIOC
#define LCD12864_RW_PIN  GPIO_Pin_2
#define LCD12864_RW_HIGH()      GPIO_SetBits(LCD12864_RW_PORT, LCD12864_RW_PIN)  
#define LCD12864_RW_LOW()      GPIO_ResetBits(LCD12864_RW_PORT, LCD12864_RW_PIN)  

#define LCD12864_RS_PORT   GPIOC
#define LCD12864_RS_PIN  GPIO_Pin_1
#define LCD12864_RS_HIGH()      GPIO_SetBits(LCD12864_RS_PORT, LCD12864_RS_PIN)  
#define LCD12864_RS_LOW()      GPIO_ResetBits(LCD12864_RS_PORT, LCD12864_RS_PIN)  

#define LCD12864_PSB_PORT   GPIOC
#define LCD12864_PSB_PIN  GPIO_Pin_12
#define LCD12864_PSB_HIGH()      GPIO_SetBits(LCD12864_RS_PORT, LCD12864_RS_PIN)  
#define LCD12864_PSB_LOW()      GPIO_ResetBits(LCD12864_RS_PORT, LCD12864_RS_PIN)  


#define xtal    72
#define left    0x18
#define right   0x1c

#define Set_CS()   LCD12864_RS_HIGH()
#define Set_SID()  LCD12864_RW_HIGH()
#define Set_SCLK() LCD12864_EN_HIGH()

#define Clr_CS()   LCD12864_RS_LOW()
#define Clr_SID()  LCD12864_RW_LOW()
#define Clr_SCLK() LCD12864_EN_LOW()


void W_1byte(u8 RW, u8 RS, u8 W_data);
void Write_8bits(u16 W_bits);
void LCD_Init0(void);
void LCD_Init1(void);
void LCD12864_Char_Set(u8 y, u8 x, u8 *p);
void Set_Draw(void);
void Draw_Pic(u8 x, u8 y, const u8 *Draw);
void bsp_lcd12864_gpio_init(void);
void bsp_lcd12864_init(void);
void Lcd_flash(u16 delay_t,u8 times);

#endif

확인하시고 답장부탁드립니다.
-----------------------------------------------
확인 부탁드립니다.
첨부파일
비밀번호 삭제하려면 비밀번호를 입력하세요.

목록

삭제 수정 답변

댓글 수정

비밀번호

수정 취소

/ byte

댓글 입력

이름 비밀번호 관리자답변보기

확인

/ byte


* 왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

회원에게만 댓글 작성 권한이 있습니다.