Суббота, Май 30, 2020

PIC18F2480

 

http://www.youtube.com/watch?v=0QItDvLOBLw


//Будем изучать CAN. Для того ,чтобы не паять свою схему, я купил дешевый Китайский
// ELM327. Выпаял светодиоды. Поднял MCRL ногу и 14,15,16 ноги. Припаял шлейф на LCD.
// Припаял переходник для программатора WinPic800
// Тестовая программа выводит на LCD то ,что печатаешь на клаве компа
// программа для работты с COMport тут http://www.chiark.greenend.org.uk/~sgtatham/putty/
#include<p18cxxx.h>
#include<delays.h>
#include<xlcd.h>
#include <usart.h>
#pragma config OSC=XT
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config MCLRE=OFF
#pragma config BOREN=OFF
#pragma config PBADEN=OFF

char str1[]="DON'T TOUCH ME ";
char str2[]="FUCK YOU SHIT ";
char count=0;
#pragma code
void DelayFor18TCY(void)
{
    Delay10TCYx(2);
}
void DelayPORXLCD(void)
{
    Delay1KTCYx(15);
}
void DelayXLCD(void)
{
    Delay1KTCYx(5);
}

void main(void)
{
    ADCON1=0;
    ADCON1=0x0f;
    //Конфигурируем LCD
    OpenXLCD(FOUR_BIT & LINES_5X7);
    while(BusyXLCD());
    WriteCmdXLCD(CURSOR_ON&BLINK_ON);
    //Конфигурируем USART
    OpenUSART( USART_TX_INT_OFF &
               USART_RX_INT_OFF &
               USART_ASYNCH_MODE &
               USART_EIGHT_BIT &
               USART_CONT_RX &
               USART_BRGH_HIGH,
               25 );
    while(BusyXLCD());           
    SetDDRamAddr(0x80);
    putsXLCD(str1);
    Delay10KTCYx(50);
    putsUSART(str1);
    while(BusyXLCD());
    SetDDRamAddr(0xC0);
    putsXLCD(str2);
    Delay10KTCYx(50);
    putsUSART(str2);
    while(1)
    {
        while (!DataRdyUSART());
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(0x01);             // Clear display
        while(BusyXLCD());
        SetDDRamAddr(0x80);
        for(count=0;count<16;count++){
            while (!DataRdyUSART());
            WriteDataXLCD(getcUSART());
        }
        while(BusyXLCD());
        SetDDRamAddr(0xC0);
        for(count=0;count<16;count++){
            while (!DataRdyUSART());
            WriteDataXLCD(getcUSART());
        }
     }
}

 



//Подправим файл xlcd.h в С18

 

#ifndef __XLCD_H
#define __XLCD_H
#include "p18cxxx.h"
/* PIC18 XLCD peripheral routines.
 *
 *   Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

 

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

 

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
#define UPPER

 

/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT      PORTB
#define TRIS_DATA_PORT TRISB

 

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
//#define RW_PIN   LATBbits.LATB6   /* PORT for RW */
//#define TRIS_RW  TRISBbits.TRISB6    /* TRIS for RW */
//#define RS_PIN   LATBbits.LATB5   /* PORT for RS */
//#define TRIS_RS  TRISBbits.TRISB5    /* TRIS for RS */
//#define E_PIN    LATBbits.LATB4   /* PORT for D  */
//#define TRIS_E   TRISBbits.TRISB4    /* TRIS for E  */

 

#define RW_PIN   LATCbits.LATC4   /* PORT for RW */
#define TRIS_RW  TRISCbits.TRISC4    /* TRIS for RW */
#define RS_PIN   LATCbits.LATC5   /* PORT for RS */
#define TRIS_RS  TRISCbits.TRISC5    /* TRIS for RS */
#define E_PIN    LATCbits.LATC3   /* PORT for D  */
#define TRIS_E   TRISCbits.TRISC3    /* TRIS for E  */

 

/* Display ON/OFF Control defines */
#define DON         0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off     */
#define CURSOR_ON   0b00001111  /* Cursor on       */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF   0b00001110  /* Cursor No Blink */

 

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00010011  /* Cursor shifts to the left   */
#define SHIFT_CUR_RIGHT   0b00001100  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT   0b00011011  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00011111  /* Display shifts to the right */

 

/* Function Set defines */
#define FOUR_BIT   0b00101111  /* 4-bit Interface               */
#define EIGHT_BIT  0b00111111  /* 8-bit Interface               */
#define LINE_5X7   0b00110011  /* 5x7 characters, single line   */
#define LINE_5X10  0b00110111  /* 5x10 characters               */
#define LINES_5X7  0b00111011  /* 5x7 characters, multiple line */

 

#define PARAM_SCLASS auto
#define MEM_MODEL far  /* Change this to near for small memory model */

 

/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(PARAM_SCLASS unsigned char);

 

/* SetCGRamAddr
 * Sets the character generator address
 */
void SetCGRamAddr(PARAM_SCLASS unsigned char);

 

/* SetDDRamAddr
 * Sets the display data address
 */
void SetDDRamAddr(PARAM_SCLASS unsigned char);

 

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

 

/* ReadAddrXLCD
 * Reads the current address
 */
unsigned char ReadAddrXLCD(void);

 

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

 

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

 

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(PARAM_SCLASS char);

 

/* putcXLCD
 * A putc is a write
 */
#define putcXLCD WriteDataXLCD

 

/* putsXLCD
 * Writes a string of characters to the LCD
 */
void putsXLCD(PARAM_SCLASS char *);

 

/* putrsXLCD
 * Writes a string of characters in ROM to the LCD
 */
void putrsXLCD(PARAM_SCLASS const MEM_MODEL rom char *);

 

/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);

 

#endif




НАЗАД                                                                                                                                         ДАЛЕЕ


Back to Top