اطلاعیه

Collapse
No announcement yet.

مشکل در ارسال سری

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در ارسال سری

    سلام
    بچه ها من می خوام با پورت سریال اطلاعات رو به کامپیوتر بفرستم ولی هر کاری می کنم چرت و پرت می فرسته نمی دونم مشکل از کجاست این برناممه
    #include <avr/io.h>
    #include <avr/iom16.h>
    #include <inttypes.h>
    #define F_OSC 4000000 /* oscillator-frequency in Hz */
    #define UART_BAUD_RATE 9600
    #define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16l)-1)
    void delay_ms(unsigned short ms) {
    unsigned short outer1, outer2;
    outer1 = 200;
    while (outer1) {
    outer2 = 1000;
    while (outer2) {
    while ( ms ) ms--;
    outer2--;
    }
    outer1--;
    }
    }
    void init(void) {
    // set baud rate
    UBRRH = (uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F_OSC)> >8);
    UBRRL = (uint8_t)UART_BAUD_CALC(UART_BAUD_RATE,F_OSC);

    // Enable receiver and transmitter; enable RX interrupt
    UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);

    //asynchronous 8N1
    UCSRC = (1 << URSEL) | (3 << UCSZ0);
    }
    int a=0x3;
    int main()
    {
    init();

    while(1)
    {

    while(!(UCSRA & (1<<UDRE)));
    UDR = ~a;


    }
    }

    این هم مدارمه فقط خازن ها رو یه خازن های دیگه گذاشتم

    #2
    پاسخ : مشکل در ارسال سری

    برای ارتباط سریال میتونید از Avrlib هم استفاده کنید.
    فایل ضمیمه رو نگاه کنید.
    کد PHP:
    //----- Include Files ---------------------------------------------------------
    #include "global.h"        // include our global settings
    #include <avr/io.h>        // include I/O definitions (port names, pin names, etc)
    #include "uart.h"        // include uart function library
    #include "rprintf.h"    // include printf function library

    //----- Begin Code ------------------------------------------------------------
    int main(void)
    {
        
    int i;
        
    // initialize our libraries
    // initialize the UART (serial port)
        
    uartInit();

        
    // set the baud rate of the UART for our debug/reporting output
        
    uartSetBaudRate(9600);

    // initialize rprintf system
        // - use uartSendByte as the output for all rprintf statements
        // this will cause all rprintf library functions to direct their
        // output to the uart
        // - rprintf can be made to output to any device which takes characters.
        // You must write a function which takes an unsigned char as an argument
        // and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
        
    rprintfInit(uartSendByte);

        
    rprintf("This is my cool program!\n");
        
        
    10;
        
    rprintf("value = %d\n", i);
        
        while(
    1);
        return 
    0;


    فایل های پیوست شده
    چگونه هوشمندانه بپرسیم

    دیدگاه


      #3
      پاسخ : مشکل در ارسال سری

      مقدار خازن ها در مدار مهم نیست؟

      دیدگاه


        #4
        پاسخ : مشکل در ارسال سری

        از 1uF تا 22uF مانعی نداره
        چگونه هوشمندانه بپرسیم

        دیدگاه

        لطفا صبر کنید...
        X