Học viết chương trình C trên AVR studio

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • quocdat_dtvt
    Thành viên tích cực
    • Nov 2007
    • 213

    #46
    các bác dùng avr studio lâu rồi thì chắc có nhiều thư viện,
    có bác nào có thư viện cho giao thức 1 dây
    và ds18b20 kô?
    bác nào có thì share cho mình với
    thank
    ĐỪNG KHÓC CHO NHỮNG GÌ ĐÃ QUA, MÀ HÃY CƯỜI CHO NHỮNG ĐIỀU SẮP TỚI!

    Comment

    • Multi System
      Thành viên tích cực
      • Feb 2008
      • 671

      #47
      Nguyên văn bởi quocdat_dtvt Xem bài viết
      các bác dùng avr studio lâu rồi thì chắc có nhiều thư viện,
      có bác nào có thư viện cho giao thức 1 dây
      và ds18b20 kô?
      bác nào có thì share cho mình với
      thank
      Moi trong Blog của mình thấy cái này, bạn đọc xem giúp ích gì không ?
      PHP Code:
      [U][COLOR="Red"]One Wire[/COLOR][/U]
      
      So, we are going to write a piece of code that implements the 1-wire protocol.
      
      Start by gathering info, the first thing to look at is the DS18B20 datasheet, get a feeling of what is about. No need to understand everything in the datasheet. On Maxim's site there are tones of application notes, I would suggest application notes 162,187,126,120, with this sequence, probably first AVR318 application note which is easy to follow. Come on, show an aggressive attitude, although you don't understand everything, I don't either. Do not copy/paste pieces of code hoping it's going to work, it will not. From the ground we go up. Try to simplify thinks by asking yourself simple questions.
      
      You see that many thermos can be connected together on a bus, a micro talks to them, so they have to be addressed with a unique ID (think ethernet & IP analogy). There is a single wire, so only one speaks at a time. Who coordinates discussion? The master, the micro (forget ethernet analogy). Well, if it does how the hell it knows which thermo is on the bus? There is an algorithm for doing that, the search algorithm. Do I care? No, not for this project, we have a single thermo on the bus. Is there a way to identify communication errors or malfunctioning thermos? The CRC does that.
      
      If you were a microcontroller, and wanted to talk over your half-duplex conference phone to your fellow thermometers, what interogation commands you would like to have? There are a few simple concepts, that reasonably fit into the puzzle. Don't bypass them.
      
      Hmm, where to start? The first think to try after getting the idea is sending 1s and 0s. Reading 1s and 0s would help too. It comes down to holding the pin for output and releasing it for input. When set for output, the pin can be written, when set for input the pin can be read ... Have a look at the following defs and see if they make any sense.
      
      // set pin mask   
      #define wmask     0x08               
      // set 1-wire pin for output
      #define wOut      DDRA |= wmask
      // set 1-wire pin for input (bus released)     
      #define wIn       DDRA &= ~wmask
      // set 1-wire bus high     
      #define wH        PORTA |= wmask
      // set 1-wire bus low     
      #define wL        PORTA &= ~wmask
      // get 1-wire bus input (bus released)   
      #define wR        PINA & wmask       
       
      
      Now, this is just pin toggling, from that we need to get to the basic bus signals. Let's go one level up. Hmm, wait a minute, it looks like we need a delay first. OK. Think of ...
      
      // delay = 5.70 + (1.22 * count)us
      void uDelay(u8 count)
      {
          while(count--);                 
      }
       
      
      This is a delay but how long does it last? You need to simulate your code with AVRStudio, please do so. Go to Debug => AVR Simulator Options => Frequency=7.3728 MHz. After compiling, Debug => Start Debugging, press F11 a couple of times and look at the stopwatch. You may reset your stopwatch by right clicking on it. I hope you get the same result as I did: delay = 5.70 + 1.22 * count microseconds for a 7.3728MHz clock. One time slot is 60us and looking at the AVR318 app. note we can realize how to output 1s and 0s....
      
      void wTxbit (u8 bit)
      {
         wOut;wL;
         if (bit)
         {
            uDelay (4);      // 10.58us
            wIn;
            uDelay (46);     // 61.82us
         }
         else
         {
            uDelay (46);     // 61.82us
            wIn;             // better releash the bus
            uDelay (4);      // 10.58us
         }
      }
       
      
      Delay constrains have to be met but, the protocol timing is not very strict. Onto the read routine ...
      
      u8 wRxbit (void)
      {
         u8 data;
      
         wOut;wL;
         uDelay (0);         // 10.58us
         wIn;
         uDelay (0);         // 10.58us
         data=wR;
         uDelay (23);        // 61.82us
      
         return data;
      }
       
      
      Your time has come, after clearly understanding the above, you have to implement the Reset/Presence signal. Lucky you! 
      

      Comment

      • vuxuanloi
        Thành viên tích cực
        • Apr 2009
        • 185

        #48
        Nguyên văn bởi thienluong
        AVR studio chủ yếu dùng để viết bằng ngôn ngữ ÁM thôi , nó rất mạnh và hay trong việc gỡ rối mô phỏng bên ASM , còn viết bằng C thì dùng CodeVisionAVR là hay nhất
        Ngày xưa khi còn học thì mình cũng đã làm tốt với codevision, nhưng cảm thấy nó không thực sự tốt vì mình phụ thuộc nhiều vào phần mềm, và mình không khoái nó lắm, sau một năm không đụng chạm gì đến, giờ không còn chữ nào trong bụng cả, hi hi, thế là mình có thể coi như tờ giấy trắng với AVR.
        Vậy thì sao nhỉ? mình bắt đầu học từ mớ i(từ sáng nay), dĩ nhiên là mình ngốn kha khá tài liệu và không nhớ gì mấy. tuy nhiên, mình thấy AVR studio tốt hơn nhiều, hỗ trợ mạnh với C/C++, bạn chỉ cần cài đặt thêm winavr là ngon, cách tốt nhất là cài winavr trước và cài avr studio sau, nếu cài avr studio trước thì ta configuration option là được mà, ^^.
        Vũ xuân Lợi
        YM!:

        Comment

        • thi tran
          Thành viên tích cực
          • Oct 2010
          • 210

          #49
          hjx , theo mình đc pít thì AVR_studio hỗ trợ cả 2 loại ngôn ngữ C và ASM mà . bạn setup WinAVR trước rồi setup AVR_studio bản full là ok mà . tha hồ mà lập trình nhá !
          ................. Pleiku .................... GIA LAI ...................

          Comment

          • ngdnhanbk
            Thành viên mới
            • Nov 2010
            • 28

            #50
            Cho em hỏi, cài AVR Studio 5 là đã tích hợp sẵn WINAVR rồi hả mấy bác?

            Comment

            • Xavan
              Thành viên mới
              • Jun 2014
              • 1

              #51
              Nguyên văn bởi schanbkhn Xem bài viết
              mình cũng mới học về AVR , nói chúng thấy cũng chẳng dễ lắm , để mà am hiểu tường tận về AVR , theo mình thì nên tham khảo qua datasheet của nó , và đọc 1 số sách tiếng anh ( mình search thấy rất ít sách tiếnh anh , sách tiếng nga thì nhiều hơn 1 chút ... )nếu chỉ đọc 1 ít sách ( tiếng việt ) thì e là không hiểu hết ..., viết code cho AVR bằng ASM , sau đó dùng AVRstudio để check ... đọc phần hướng dẫn sử dụng của nó thì cũng khá đầy đủ ... tuy nhiên , cũng có nhiều điều chưa biết về mấy cái này , chịu khó hỏi cũng có nhiều anh em giúp đỡ ...
              Nhưng dù sao thì chúng ta cũng cần 1 trình biên dịch đủ tốt để viết code
              Mình bắt đầu viết bằng C cho avrstudio,nhìn chung còn hạn chế
              Bạn có thể chỉ cho mình tìm hiểu các câu lệnh của avrstudio 6 không? thank

              Comment

              Về tác giả

              Collapse

              chi_co_nui Tìm hiểu thêm về chi_co_nui

              Bài viết mới nhất

              Collapse

              Đang tải...