2017-05-06 17 views
0

4D 시스템의 gen4 uLCD-70dt 및 PIC18F8722to를 사용하는 프로젝트에서 작업하고 있습니다. 두 디바이스는 한 쌍의 MAX232 직렬 드라이버를 사용하여 연결된다.4D 시스템과의 PIC18F8722 시리얼 통신 uLCD-70-DT

이전에 PIC18F4520을 사용하여이 설정을 브레드 보드했고 시리얼 통신에 문제가 없었습니다. 이제 PIC가 디스플레이에 폴링 요청을 보내면 디스플레이는 응답하지만 PIC는 데이터를 수신하지 않습니다. 코드 ID는 매우 간단합니다 (테스트 용). 그리고 스코프를 사용하는 PIC 핀에서 데이터 스트림, RX RXD TX를 모두 검사했는데 신호가 정상적으로 보입니다. (전압 및 전송 속도 체크 아웃)

나는 온라인에서 발견 된 18F4520 용으로 구축 된 GenieSerial.h를 사용했고 18f8722에 맞게 조정했습니다. (여기에 오류가있을 수 있습니다)

구성 비트 또는 EUSART 설정 비트에 오류가있는 것으로 추측합니다. 어떤 도움이

을 apreciated입니다

홈페이지 코드 :

/* 
    * File: trial1.c 
    * Author: Steve 
    * 
    * Created on May 2, 2017, 3:06 PM 
    */ 

// PIC18F8722 Configuration Bit Settings 

// 'C' source line config statements 

// CONFIG1H 
#pragma config OSC = HS   // Oscillator Selection bits (External RC  oscillator, CLKO function on RA6) 
#pragma config FCMEN = OFF  // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) 
#pragma config IESO = OFF  // Internal/External Oscillator Switchover bit (Two-Speed Start-up disabled) 

// CONFIG2L 
#pragma config PWRT = OFF  // Power-up Timer Enable bit (PWRT disabled) 
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled)) 
#pragma config BORV = 3   // Brown-out Voltage bits (Minimum setting) 

// CONFIG2H 
#pragma config WDT = OFF  // Watchdog Timer (WDT disabled (control is placed on the SWDTEN bit)) 
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768) 

// CONFIG3L 
#pragma config MODE = MC  // Processor Data Memory Mode Select bits (Microcontroller mode) 
#pragma config ADDRBW = ADDR20BIT// Address Bus Width Select bits (20-bit Address Bus) 
#pragma config DATABW = DATA16BIT// Data Bus Width Select bit (16-bit External Bus mode) 
#pragma config WAIT = OFF  // External Bus Data Wait Enable bit (Wait selections are unavailable for table reads and table writes) 

// CONFIG3H 
#pragma config CCP2MX = PORTC // CCP2 MUX bit (ECCP2 input/output is multiplexed with RC1) 
#pragma config ECCPMX = PORTE // ECCP MUX bit (ECCP1/3 (P1B/P1C/P3B/P3C) are multiplexed onto RE6, RE5, RE4 and RE3 respectively) 
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation) 
#pragma config MCLRE = ON  // MCLR Pin Enable bit (MCLR pin enabled; RG5 input pin disabled) 

// CONFIG4L 
#pragma config STVREN = ON  // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) 
#pragma config LVP = ON   // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled) 
#pragma config BBSIZ = BB2K  // Boot Block Size Select bits (1K word (2 Kbytes) Boot Block size) 
#pragma config XINST = OFF  // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode)) 

// CONFIG5L 
#pragma config CP0 = OFF  // Code Protection bit Block 0 (Block 0 (000800, 001000 or 002000-003FFFh) not code-protected) 
#pragma config CP1 = OFF  // Code Protection bit Block 1 (Block 1 (004000-007FFFh) not code-protected) 
#pragma config CP2 = OFF  // Code Protection bit Block 2 (Block 2 (008000-00BFFFh) not code-protected) 
#pragma config CP3 = OFF  // Code Protection bit Block 3 (Block 3 (00C000-00FFFFh) not code-protected) 
#pragma config CP4 = OFF  // Code Protection bit Block 4 (Block 4 (010000-013FFFh) not code-protected) 
#pragma config CP5 = OFF  // Code Protection bit Block 5 (Block 5 (014000-017FFFh) not code-protected) 
#pragma config CP6 = OFF  // Code Protection bit Block 6 (Block 6 (01BFFF-018000h) not code-protected) 
#pragma config CP7 = OFF  // Code Protection bit Block 7 (Block 7 (01C000-01FFFFh) not code-protected) 

// CONFIG5H 
#pragma config CPB = OFF  // Boot Block Code Protection bit (Boot Block (000000-0007FFh) not code-protected) 
#pragma config CPD = OFF  // Data EEPROM Code Protection bit (Data EEPROM not code-protected) 

// CONFIG6L 
#pragma config WRT0 = OFF  // Write Protection bit Block 0 (Block 0 (000800, 001000 or 002000-003FFFh) not write-protected) 
#pragma config WRT1 = OFF  // Write Protection bit Block 1 (Block 1 (004000-007FFFh) not write-protected) 
#pragma config WRT2 = OFF  // Write Protection bit Block 2 (Block 2 (008000-00BFFFh) not write-protected) 
#pragma config WRT3 = OFF  // Write Protection bit Block 3 (Block 3 (00C000-00FFFFh) not write-protected) 
#pragma config WRT4 = OFF  // Write Protection bit Block 4 (Block 4 (010000-013FFFh) not write-protected) 
#pragma config WRT5 = OFF  // Write Protection bit Block 5 (Block 5 (014000-017FFFh) not write-protected) 
#pragma config WRT6 = OFF  // Write Protection bit Block 6 (Block 6 (01BFFF-018000h) not write-protected) 
#pragma config WRT7 = OFF  // Write Protection bit Block 7 (Block 7 (01C000-01FFFFh) not write-protected) 

// CONFIG6H 
#pragma config WRTC = OFF  // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected) 
#pragma config WRTB = OFF  // Boot Block Write Protection bit (Boot Block (000000-007FFF, 000FFF or 001FFFh) not write-protected) 
#pragma config WRTD = OFF  // Data EEPROM Write Protection bit (Data EEPROM not write-protected) 

// CONFIG7L 
#pragma config EBTR0 = OFF  // Table Read Protection bit Block 0 (Block 0 (000800, 001000 or 002000-003FFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR1 = OFF  // Table Read Protection bit Block 1 (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR2 = OFF  // Table Read Protection bit Block 2 (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR3 = OFF  // Table Read Protection bit Block 3 (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR4 = OFF  // Table Read Protection bit Block 4 (Block 4 (010000-013FFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR5 = OFF  // Table Read Protection bit Block 5 (Block 5 (014000-017FFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR6 = OFF  // Table Read Protection bit Block 6 (Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks) 
#pragma config EBTR7 = OFF  // Table Read Protection bit Block 7 (Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks) 

// CONFIG7H 
#pragma config EBTRB = OFF  // Boot Block Table Read Protection bit (Boot Block (000000-007FFF, 000FFF or 001FFFh) not protected from table reads executed in other blocks) 

// #pragma config statements should precede project file includes. 
// Use project enums instead of #define for ON and OFF. 

#include <xc.h> 
#include "GenieSerial.h" 
#define _XTAL_FREQ 20000000 


// MAIN PROGRAM LOOP 

void main() 
{ 
    unsigned char incoming=37; 

    usart(); 

    while(1) 
    { 


     incoming = genieread(0x04,0x00);  //read slider 0 
     __delay_ms(104); 
     geniewrite_coolgauge(0x00, incoming); //send data back to display here 
     __delay_ms(104); 

    } 
}` 

과 GenieSerial.h 다음 GenieSerial.h 모두 보내고 더 인터럽트 핸들러 없지만 인터럽트를받을 수 있습니다

#define READ     0x00 
#define WRITE     0x01 


//objects 

#define DIPSWITCH    0x00 
#define KNOB     0x01 
#define ROCKERSW    0x02 
#define ROTARYSW    0x03 
#define SLIDER     0x04 
#define TRACKBAR    0x05 
#define BUTTON     0x06 
#define ANGULAR_METER   0x07 
#define COOL_GAUGE    0x08 
#define CUSTOM_DIGITS   0x09 
#define FORM     0x0A 
#define GAUGE     0x0B 
#define IMAGE     0X0C 
#define KEYBOARD    0X0D 
#define LED      0X0E 
#define LED_DIGITS    0X0F 
#define METER     0X10 
#define STRINGS     0X11 
#define THERMOMETER    0X12 
#define USER_LED    0X13 
#define VIDEO     0X14 
#define STATIC_TEXT    0X15 
#define SOUND     0X16 
#define TIMER     0X17 
#define CONTRAST    0x04 
#define PLAY     0X00 
#define STOP     0x04 
#define ON      0X01 
#define OFF      0x00 
#define VIDEOPLAY    0X01 
#define VIDEOSTOP    0X00 

void usart(void) 
{ 
    INTCONbits.GIE=1; //enable global interrupts 
    INTCONbits.PEIE=1; //enable peripheral interrupts 
    TRISCbits.TRISC7=1; //Make UART RX pin input 
    TRISCbits.TRISC6=0; //Make UART TX pin output 
    SPBRGH = 0x00 ;  //9600bps 20MHz Osc 
    SPBRG = 31; 

    RCSTA1bits.CREN=1; //1 = Enables receiver 
    RCSTA1bits.SPEN=1; //1 = Serial port enabled (configures RX/DT and TX/CK pins as serial port pins) 
    BAUDCON1bits.BRG16=0;//0 = 8-bit Baud Rate Generator ? SPBRGH and SPBRG 
    BAUDCON1bits.ABDEN=0; 

    TXSTA1bits.SYNC=0; //0 = Asynchronous mode 
    TXSTA1bits.BRGH=0; //0 = low speed 
    TXSTA1bits.SENDB = 0; 
    BAUDCON1bits.WUE =0; 
    PIE1bits.TXIE = 1; 
    PIE1bits.RC1IE =1; 

} 

    /////////////////////////////////////////// 

unsigned char receive(void) 
{ 
    unsigned char data; 
    if(RCSTAbits.FERR==1 && RCSTAbits.OERR==1) 
    { 
     while(PIR1bits.RCIF == 1) 
     { 
      RCSTAbits.CREN =0; //Overrun error (can be cleared by clearing bit CREN) 
      data = RCREG; 
      RCSTAbits.CREN =1; 
     } 
    } 
    else 
    { 
     while(PIR1bits.RCIF == 1) 
     { 
      RCSTAbits.CREN =0; //Overrun error (can be cleared by clearing bit CREN) 
      data = RCREG; 
      RCSTAbits.CREN =1; 
     } 
    } 
    return data; 
} 

void send(void) 
{ 
    TXSTAbits.TXEN=0; 
     while(TXSTAbits.TRMT == 0) 
     { 
       TXSTAbits.TXEN=1; // enable transmission 
       while(TXSTAbits.TRMT == 0) // wait here till transmit complete 
       { 
       } 
     } 
    TXSTAbits.TXEN=0; 
} 

    /////////////////////////////////////////////// 

void sendbyte(unsigned char data) 
{ 
    TXREG = data; 
    TXSTAbits.TXEN=0; 
     while(TXSTAbits.TRMT == 0) 
     { 
       TXSTAbits.TXEN=1; // enable transmission 
       while(TXSTAbits.TRMT == 0) // wait here till transmit complete 
       { 
       } 
     } 
    TXSTAbits.TXEN=0; 
} 



void sendarray(unsigned char value, unsigned char value2, unsigned char value3,unsigned char value4,unsigned int value5) 
{ 
     TXREG = value; 
     send(); 
     TXREG = value2; 
     send(); 
     TXREG = value3; 
     send(); 
     TXREG = value4; 
     send(); 
     TXREG = value5; 
     send(); 
     TXREG = (value^value2^value3^value4^value5); 
     send(); 
} 

void geniewrite_coolgauge(unsigned char index, unsigned char value)     // write cool gauge object with a value of 0-255 
{ 
     TXREG = WRITE;  send(); 
     TXREG = COOL_GAUGE; send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^COOL_GAUGE^index^0x00^value); send(); 
} 
void geniewrite_gauge(unsigned char index, unsigned char value) 
{ 
     TXREG = WRITE;  send(); 
     TXREG = GAUGE;  send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^GAUGE^index^0x00^value);  send(); 
} 
void geniewrite_slider(unsigned char index, unsigned char value) 
{ 
     TXREG = WRITE;  send(); 
     TXREG = SLIDER;  send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^SLIDER^index^0x00^value);  send(); 
} 
void geniewrite_meter(unsigned char index, unsigned char value) 
{ 
     TXREG = WRITE;  send(); 
     TXREG = METER;  send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^METER^index^0x00^value);  send(); 
} 
void geniewrite_winbutton(unsigned char index, unsigned char value) 
{ 
     TXREG = WRITE;  send(); 
     TXREG = BUTTON;  send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^BUTTON^index^0x00^value);  send(); 
} 

void geniewrite_dipswitch(unsigned char index, unsigned char value) 
{ 
     TXREG = WRITE;  send(); 
     TXREG = DIPSWITCH; send(); 
     TXREG = index;  send(); 
     TXREG = 0x00;  send(); 
     TXREG = value;  send(); 
     TXREG = (WRITE^DIPSWITCH^index^0x00^value);  send(); 
} 
void geniewrite_knob(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = KNOB;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^KNOB^index^0x00^value);  send(); 
} 
void geniewrite_rockerswitch(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG =ROCKERSW;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^ROCKERSW^index^0x00^value); send(); 
} 
void geniewrite_rotaryswitch(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = ROTARYSW; send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^ROTARYSW^index^0x00^value);  send(); 
} 
void geniewrite_trackbar(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = TRACKBAR;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^TRACKBAR^index^0x00^value);  send(); 
} 
void geniewrite_keyboard(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = KEYBOARD; send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^KEYBOARD^index^0x00^value);  send(); 
} 
void geniewrite_angularmeter(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;   send(); 
      TXREG = ANGULAR_METER; send(); 
      TXREG = index;   send(); 
      TXREG = 0x00;   send(); 
      TXREG = value;   send(); 
      TXREG = (WRITE^ANGULAR_METER^index^0x00^value);  send(); 
} 
void geniewrite_thermometer(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = THERMOMETER; send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^THERMOMETER^index^0x00^value);  send(); 
} 
void geniewrite_LED(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = LED;   send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^LED^index^0x00^value);  send(); 
} 
void geniewrite_userLED(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = USER_LED; send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^USER_LED^index^0x00^value);  send(); 
} 
void geniewrite_LEDdigits(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = LED_DIGITS; send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^LED_DIGITS^index^0x00^value);  send(); 
} 
void geniewrite_customdigits(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = CUSTOM_DIGITS;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE ^CUSTOM_DIGITS^index^0x00^value);  send(); 
} 
void geniewrite_string(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = STRINGS;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^STRINGS^index^0x00^value);  send(); 
} 
void geniewrite_form(unsigned char index) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = FORM;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = (WRITE^FORM^index^0x00^0x00);  send(); 
} 
void geniewrite_videoGIF(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = VIDEO;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^VIDEO^index^0x00^value);  send(); 
} 
void geniewrite_timer(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = TIMER;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE ^TIMER^index^0x00^value);  send(); 
} 
void geniewrite_sound(unsigned char index, unsigned char value) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = SOUND;  send(); 
      TXREG = index;  send(); 
      TXREG = 0x00;  send(); 
      TXREG = value;  send(); 
      TXREG = (WRITE^TIMER^index^0x00^value);  send(); 
} 
void geniewrite(unsigned char value, unsigned char value2) 
{ 
      TXREG = WRITE;  send(); 
      TXREG = value;  send(); 
      TXREG = value2;  send(); 
      TXREG = (WRITE^CONTRAST^value);  send(); 
} 

unsigned char genieread(unsigned char object, unsigned char index) 
{ 
    unsigned char data, data1, data2, data3, data4, data5;  
    TXREG = READ;    send(); 
    TXREG = object;    send(); 
    TXREG = index;    send(); 
    TXREG = (READ^object^index); send(); 

    data = receive(); 
    data1 = receive(); 
    data2 = receive(); 
    data3 = receive(); 
    data4 = receive(); 
    data5 = receive(); 
    return data4; 
} 
+0

그림의 직렬 포트를 rs232-usb 어댑터에 연결하면 어떻게됩니까? 터미널 클라이언트가 예상 데이터를 표시합니까? 그리고 당신이 그림 데이터를 보낼 때 그것을 받습니까? – imqqmi

답변

0

. 인터럽트 플래그가 제대로 재설정되지 않으면 문제가 발생할 수 있습니다. 내가 먼저 인터럽트를 비활성화하고 그것을 정리할 경우 볼 것 :

PIE1bits.TXIE = 0; 
PIE1bits.RC1IE = 0; 

을 단지 직렬 포트를 처리하기 위해 폴링을 사용하고 있기 때문에, 인터럽트를 사용하지 않도록하는 것이 좋습니다.

또한 오실레이터가 예상되는 주파수로 작동하는지 확인하십시오. 데이터 시트에 따르면 직렬 포트는 9766 보드에서 실행됩니다. 이것이 문제를 야기하지 않는지 확인하십시오. BRGH = 1 및 SPBRG = 129 인 20MHz의 대체 설정을 사용하여 속도를 9615 보 (baud)로 설정합니다. 이는 9600 보오 (baud) 스펙에 더 가깝습니다. 데이터 시트 (39646c.pdf)의 253 페이지를 참조하십시오.