เขียนฟังก์ชั้นเขียนข้อความใน lcd

Started by derp, May 18, 2013, 01:09:21 PM

Previous topic - Next topic

derp

ผมอยากสร้างฟังก์ชั่นที่เขียนข้อความบนจอ lcd ได้อ่ะครับ อยากให้ใช้ได้เหมือน printf คือใส่ %d %c ลงไปในสตริงได้แล้วปรินท์ออกมาตามตัวแปรข้างหลัง ใช้ yagarto + eclipse อยู่ครับ มีใครแนะนำวิธีเขียนได้มั๊ยครับ ขอบคุณครับ

ปล. เหมือนว่าใน compiler นี้มันจะ include พวก stdio.h, string.h, stdarg.h ไม่ได้อ่ะครับ เลยมีปัญหา

wlasoi

keyword "retarget" ... หา standard  input , output function ให้เจอ

putc();
getc();

แก้ให้ รับ/ส่ง ค่าเข้ากับ output/inoput ที่เราสร้างขึ้น .. ส่งออกได้ทุกทางไม่ใช่เฉพาะ uart,lcd  อันนี้ของ PIC gcc style มี write กับ read มันจะประกาศไว้ใน Header file แต่ตัว function จะ blank ของ ARM ก็น่าจะคล้ายๆ .. หาให้เจอว่า std input/output ของ libary มันคืออะไร ทำการ force libary (เขียนทับ function เดิม) ซ่ะ .. โดยอ้างอิง argrument ของเดิม และ ดูการบังคับ  Handler output  .. ต้องอ่าน manual ให้ล่ะเอียด ครับ มีแน่ๆ ผมเคยเขียนอยู่ของ arm

Quote#include  <p24fj128GB110.h>     
#include  <stdio.h> 

#include  "..\h\hardware.h"
#include  "..\h\uart.h"
#include  "..\h\lcd.h"

enum my_handles {
    handle_stdin,      // 0
    handle_stdout,     // 1
    handle_stderr,     // 2
    handle_uart1,      // 3
    handle_uart2,      // 4
    handle_lcd,        // 5
};

//stdio.h config.
#define     flushBuffer_enable  0     //0-disable,1-enable

#ifndef  flushBuffer_enable
    #define  flushBuffer_enable    0
    #warning not #define flushBuffer_enable , default  ' #define flushBuffer_enable    0
#endif

#if  flushBuffer_enable == 1
    #define  buf_Size           32
    #define  indicateFullBuf    _IOFBF
    #define  indicateLineBuf    _IOLBF
    #define  indicateNoBuf      _IONBF
#endif

#if flushBuffer_enable  == 1
    volatile char buf[buf_Size];
#endif

//

int __attribute__((__weak__, __section__(".libc"))) open(const char
*name, int access, int mode)
{
      switch (name[0]){

         case 'i' : return handle_stdin;
         case 'o' : return handle_stdout;
         case 'e' : return handle_stderr;
         case 'u' : return handle_uart1;
         case 'c' : return handle_uart2;
         case 'L' : return handle_lcd;
         default  : return handle_stderr;
      }
}


int __attribute__((__weak__, __section__(".libc"))) write(int handle, void *buffer, unsigned int len){
   int i;
   switch (handle){

        // case select default stdio.h
        case  0   :  break;

        case  1   :  //STD-OUT
                     for (i = len; i; --i){
                        std_putc();
                     }   
                     break;

        case  handle_lcd  : // case select lcd-io for stdio.h
                           for (i = len; i; --i)
                                lcd_putc( *(char*)buffer);
                           break;

        case  handle_uart1 :
                    #if uart1_enable  == 1
                    for (i = len; i; --i)
                       _uart1_putc( *(char*)buffer);
                    #endif
                    break;

        case  handle_uart2 :
                   #if uart2_enable  == 1
                   for (i = len; i; --i)
                       _uart2_putc( *(char*)buffer);
                   #endif
                    break;


       default    : break;         // case NULL
   }
   return(len);
}

//**************************************************************************//

int __attribute__((__weak__, __section__(".libc"))) read(int handle, void *buffer, unsigned int len){
  int i;
  int nTimeout;

   switch (handle){

       case 0  :  for (i = len; i; --i)
                 {
                      nTimeout = 16*64; // Timeout is 16 cycles per 10-bit char
                      
                   while (! stdin_ready() && nTimeout )
                         --nTimeout;   
                         std_read();
                 }
                 len -= i;
                 break;

        default : break;

   }
   return(len);
}



// #if !defined(_SIZE_T) && !defined(_SIZET)
//   && !defined(_BSD_SIZE_T_DEFINED_)
//  #define _SIZE_T
//  #define _SIZET
//  #define _BSD_SIZE_T_DEFINED_
//  #define _STD_USING_SIZE_T


// end of Files

Paekung

ให้ทำฟังชั่นส่ง byte ให้ได้ก่อนครับ แล้วค่อยทำ prototype
ตัวอย่างก็ตามนี้ครับ
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(EVAL_COM1, (uint8_t) ch);

  /* Loop until transmit data register is empty */
  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET)
  {}

  return ch;
}

ถ้าจะใช้ scanf ก็ทำ getch() มาอีกตัวครับ
รับเขียนโปรแกรม ออกแบบวงจร ไปจนถึง PCB
ไมโคร : 8/16/32 bit  ทุกตระกูล
สนใจติดต่อ
saintentex@gmail.com
หรือ 081-1846590


derp

ขอบคุณมากครับ จะลองศึกษาดูครับ