NOTICE توجه: این یک موضوع قدیمی است که آخرین پست ارسالی آن مربوط به 3028 روز قبل است . لطفا فقط پاسخ ها ، سوالات و درخواست های 100 درصد مرتبط را به آن ارسال کنید و برای درخواست ها و سوالات جدید موضوع جدیدی را ایجاد کنید
نمایش نتایج: از 1 به 2 از 2

موضوع: درست کردن هدر فایل lcd

  1. #1
    تازه وارد
    تاریخ عضویت
    Jan 2016
    نوشته ها
    2
    تشکر
    0
    تشکر شده 0 بار در 0 پست

    پیش فرض درست کردن هدر فایل lcd (حل شد)

    سلام
    برای کامپایلر XC8 هدر فایل LCD کاراکتری نوشتم اما متاسفانه کار نمیکنه! نمیدونم مشکلش دقیقا چی هست، کسی میتونه راهنمایی بکنه؟

    lcd.h

    کد:
    
    
    
    1. #ifndef XC_HEADER_TEMPLATE_H
    2. #define XC_HEADER_TEMPLATE_H
    3. #include <xc.h> // include processor files - each processor file is guarded.
    4. #define _XTAL_FREQ 4000000
    5. // TODO Insert appropriate #include <>
    6. // TODO Insert C++ class definitions if appropriate
    7. // TODO Insert declarations
    8. // TODO Insert declarations or function prototypes (right here) to leverage
    9. // live documentation
    10. #ifdef __cplusplus
    11. extern "C" {
    12. #endif /* __cplusplus */
    13. // TODO If C++ is being used, regular C code needs function names to have C
    14. // linkage so the functions can be used by the c code.
    15. #define LCD_RS RA3
    16. #define LCD_EN RA4
    17. #define LCD_DATA4 RB0
    18. #define LCD_DATA5 RB1
    19. #define LCD_DATA6 RB2
    20. #define LCD_DATA7 RB3
    21. #define LCD_RS_Direction TRISA3
    22. #define LCD_EN_Direction TRISA4
    23. #define LCD_DATA4_Direction TRISB0
    24. #define LCD_DATA5_Direction TRISB1
    25. #define LCD_DATA6_Direction TRISB2
    26. #define LCD_DATA7_Direction TRISB3
    27. void LCD_STROBE(void){
    28. LCD_EN = 1;
    29. __delay_ms(1);
    30. LCD_EN = 0;
    31. __delay_ms(50);
    32. }
    33. void LCD_write(unsigned char data){
    34. if(data & 1)
    35. LCD_DATA4 = 1;
    36. else
    37. LCD_DATA4 = 0;
    38. if(data & 2)
    39. LCD_DATA5 = 1;
    40. else
    41. LCD_DATA5 = 0;
    42. if(data & 4)
    43. LCD_DATA6 = 1;
    44. else
    45. LCD_DATA6 = 0;
    46. if(data & 8)
    47. LCD_DATA7 = 1;
    48. else
    49. LCD_DATA7 = 0;
    50. //return;
    51. }
    52. void LCD_cmd(unsigned char cmd){
    53. //unsigned char cmd_entry = cmd;
    54. /*LCD_DATA4 = (cmd >> 0) & 0x01;
    55. LCD_DATA5 = (cmd >> 1) & 0x01;
    56. LCD_DATA6 = (cmd >> 2) & 0x01;
    57. LCD_DATA7 = (cmd >> 3) & 0x01;*/
    58. LCD_RS = 0;
    59. LCD_write(cmd);
    60. LCD_STROBE();
    61. //return;
    62. }
    63. void LCD_char(char c){
    64. char temp,y;
    65. temp = c&0x0F;
    66. y = c&0xF0;
    67. LCD_RS = 1;
    68. LCD_write(y>>4);
    69. LCD_STROBE();
    70. LCD_write(temp);
    71. LCD_STROBE();
    72. }
    73. void LCD_string(char *s){
    74. //LCD_RS = 1;
    75. for (int i = 0; s[i] != '\0'; i++) {
    76. LCD_char(s[i]);
    77. }
    78. }
    79. void LCD_clear(void){
    80. LCD_cmd(0x01); //clear
    81. }
    82. void LCD_goto(void){
    83. LCD_cmd(0x80); //cursor(0,0)
    84. }
    85. void LCD_init(void){
    86. LCD_RS_Direction = 0;
    87. LCD_EN_Direction = 0;
    88. LCD_DATA4_Direction = 0;
    89. LCD_DATA5_Direction = 0;
    90. LCD_DATA6_Direction = 0;
    91. LCD_DATA7_Direction = 0;
    92. LCD_cmd(0x28); //4-bit
    93. __delay_ms(1);
    94. LCD_cmd(0x01); //clear
    95. __delay_ms(1);
    96. LCD_cmd(0x0E); //cursor on
    97. __delay_ms(1);
    98. LCD_cmd(0x80); //cursor(0,0)
    99. __delay_ms(1);
    100. //return;
    101. }
    102. #ifdef __cplusplus
    103. }
    104. #endif /* __cplusplus */
    105. #endif /* XC_HEADER_TEMPLATE_H */


    main.c
    کد:
    
    
    1. #define _XTAL_FREQ 4000000
    2. #include <pic16f88.h>
    3. #include <stdio.h>
    4. #include <stdlib.h>
    5. #include <xc.h>
    6. #include "lcd.h"
    7. #pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
    8. #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
    9. #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
    10. #pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
    11. #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    12. #pragma config CPD = OFF // Data EE Memory Code Protection bit (Code protection off)
    13. #pragma config CP = OFF
    14. //TRISB
    15. void main(void){
    16. //TRISB6 = 0;
    17. LCD_init();
    18. LCD_goto();
    19. while (1) {
    20. //LED();
    21. LCD_string("Hello World");
    22. }
    23. }

    ویرایش توسط mhsd : 13-01-2016 در ساعت 00:04

  2. # ADS
    Circuit advertisement
    تاریخ عضویت
    Always
    نوشته ها
    Many
     

  3. #2
    تازه وارد
    تاریخ عضویت
    Jan 2016
    نوشته ها
    2
    تشکر
    0
    تشکر شده 0 بار در 0 پست

    پیش فرض

    بالاخره تونستم حلش کنم!!!
    مشکل از این بود که من از پورت A برای EN و RS استفاده میکردم، پورت A آنالوگ است باید مقدار بیت های دو پین EN و RS را صفر در نظر میگرفتم تا پورت دیجیتال ست بشه!

    وقتی که بیت ها دیجیتال ست نشده!


    کد رو هم کمی تغییر دادم

    lcd.h
    کد:
    #ifndef XC_HEADER_TEMPLATE_H
    
    #define    XC_HEADER_TEMPLATE_H
    #include <xc.h> // include processor files - each processor file is guarded. 
    #define _XTAL_FREQ 4000000
    #include <pic16f88.h>
    // TODO Insert appropriate #include <>
    
    // TODO Insert C++ class definitions if appropriate
    
    // TODO Insert declarations
    
    // Comment a function and leverage automatic documentation with slash star star
    /**
     */
    // TODO Insert declarations or function prototypes (right here) to leverage 
    // live documentation
    
    #ifdef    __cplusplus
    extern "C" {
    #endif /* __cplusplus */
    
        // TODO If C++ is being used, regular C code needs function names to have C 
        // linkage so the functions can be used by the c code.
    #define LCD_RS RA3
    #define LCD_EN RA4
    #define LCD_DATA4 RB0
    #define LCD_DATA5 RB1
    #define LCD_DATA6 RB2
    #define LCD_DATA7 RB3
    #define LCD_PORT PORTB
        
        void LCD_STROBE(void){
            LCD_EN = 1;
            __delay_us(1);
            LCD_EN = 0;        
        }
        void write(unsigned char value){
            LCD_DATA4 = (value >> 0) & 0x01;
            LCD_DATA5 = (value >> 1) & 0x01;
            LCD_DATA6 = (value >> 2) & 0x01;
            LCD_DATA7 = (value >> 3) & 0x01;
            LCD_EN = 1;
            __delay_us(1);
            LCD_EN = 0;
        }
        void LCD_cmd(unsigned char data){
            LCD_RS = 0;
            __delay_us(50);
            LCD_PORT = (data >> 4);
            LCD_STROBE();
            LCD_PORT = (data);
            LCD_STROBE();
        }
        void LCD_goto(void){
            LCD_cmd(0x80);
            __delay_ms(2);
        }
        void LCD_clear(void){
            LCD_cmd(0x01);
            __delay_ms(2);
        }
        void LCD_char(unsigned char data){
            LCD_RS = 1;
            __delay_us(50);
            write(data >> 4);
            write(data);
        }
        void LCD_putc(unsigned char data){
            LCD_RS = 1;
            __delay_us(50);
            LCD_PORT = (data >> 4);
            LCD_STROBE();
            LCD_PORT = (data);
            LCD_STROBE();
        }
        void LCD_putcs(const char *data){
            while (*data) {
                LCD_putc(*data++);
            }
        }   
        void LCD_init(void){
            TRISA3 = 0;
            TRISA4 = 0;
            TRISB = 0b11110000;
            
            LCD_cmd(0x20); //4-bit 1 line, 2 line= 0x28
            __delay_ms(1);
            LCD_cmd(0x0c);
            __delay_ms(1);
            LCD_cmd(0x06); //cursor on
            __delay_ms(2);
            LCD_cmd(0x80); //cursor(0,0)
            __delay_ms(2);
            LCD_cmd(0x01); //clear
            __delay_ms(2);
        }
    #ifdef    __cplusplus
    }
    #endif /* __cplusplus */
    #endif    /* XC_HEADER_TEMPLATE_H */
    main.c
    کد:
    #define _XTAL_FREQ 4000000
    #include <pic16f88.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <xc.h>
    #include "lcd.h"
    #pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
    #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
    #pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
    #pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    #pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
    #pragma config CP = OFF
    //TRISB
    void main(void){
        //TRISB6 = 0;
        ANS3 = 0; //set RA3 to digital I/O
        ANS4 = 0; //set RA4 to digital I/O
        LCD_init();
        LCD_goto();
        LCD_putc('2');
        __delay_ms(1000);
        while (1) {
            LCD_clear();
            LCD_goto();
            LCD_char('P');
            __delay_ms(5000);
            LCD_clear();
            LCD_putcs("HELLO WORLD");
            __delay_ms(5000);
            LCD_clear();
        }
    }
    ویرایش توسط mhsd : 13-01-2016 در ساعت 00:01

موضوعات مشابه

  1. [درخواست] درخواست راهنمایی د رمورد تولید انواع بالاست و درایورهای ال ای دی
    توسط Phoenix_9821 در انجمن طراحی و ساخت و آزمایش مدارت الکترونیک
    پاسخ: 2
    آخرين نوشته: 17-08-2015, 01:39
  2. پاسخ: 2
    آخرين نوشته: 30-07-2014, 19:47

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •