久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5285|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

老外的M8 mini邏輯分析儀制作資料

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:367645 發(fā)表于 2018-7-9 10:38 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
網(wǎng)上找的一個老外的作品,用AVR M8做的一個簡易的邏輯分析儀,適合有一定單片機基礎(chǔ)的學(xué)習(xí)者參考學(xué)習(xí)。喜歡的可以自己玩玩。

制作出來的實物圖如下:


單片機源程序如下:
  1. /*
  2. ** Four-channel mini logic analyzer.
  3. **
  4. ** Target: ATmega8 at 16MHz crystal
  5. **
  6. ** Input pins PD0-PD3
  7. **
  8. ** Frimware v1.00 was written by Vassilis Serasidis on 01 January 2012.
  9. ** avrsite@yahoo.gr, info@serasidis.gr
  10. **
  11. ** IDE: AVRstudio 4.18 with AVR-gcc plugin (WinAVR-20100110).
  12. **
  13. ** Nokia 3310 / 5110 gLCD library (84*48 pixels) was written by Tony Myatt - 2007
  14. ** Small modifications to the gLCD source code library had been made by Vassilis Serasidis.
  15. **
  16. ** 3310/5110 LCD is connected on AVR's PORT B
  17. ** See <lcd.h> file for pins assignment between AVR and 3310/5110 LCD.
  18. **
  19. **   Nokia LCD    ATmega8
  20. **  ------------  -------
  21. **  LCD_CLK_PIN     PB4
  22. **  LCD_DATA_PIN    PB3
  23. **  LCD_DC_PIN      PB2
  24. **  LCD_RST_PIN     PB1
  25. **  LCD_CE_PIN      PB0
  26. **       
  27. **
  28. */
  29. #include <avr/io.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <util/delay.h>
  34. #include <avr/pgmspace.h>
  35. #include "lcd.h"
  36. #include "introScreen.h"
  37. #include "createdBy.h"

  38. #define BUFFER_SIZE  870  // 290 Sample transitions * 3 bytes for each sample = 870 bytes.
  39. #define POSITIONS_LENGTH 19004860 //BUFFER_SIZE * (MAX_SAMPLE_TIME/3) = (870/3) * 65534 = 19004860
  40. #define ONE_LINE_LENGTH  84
  41. #define MAX_SAMPLE_TIME 65534
  42. #define IN1 0
  43. #define IN2 1
  44. #define IN3 2
  45. #define IN4 3
  46. #define ONE  32
  47. #define ZERO  4
  48. #define TRANSITION 60
  49. #define MIDDLE 36
  50. #define FALSE 1
  51. #define TRUE 0

  52. #define BTN_INCREASE   PD4
  53. #define BTN_DECREASE   PC5
  54. #define BTN_ZOOM_OUT   PD5
  55. #define LED1           PB5

  56. char dataBuffer[BUFFER_SIZE];
  57. volatile unsigned int  i, counter, bufferUsedSpace, zoom, minSampleTime;
  58. volatile unsigned long  samplesPos;
  59. char int2str[8];

  60. void checkIfNoButtonIsPressed (void);
  61. void checkDecreaseButton (void);
  62. void checkIncreaseButton (void);
  63. void printCapturedData (unsigned long position, unsigned char inputChannel);
  64. void printRuler (void);
  65. void saveSampleToBuffer (void);
  66. void checkInputs (void);
  67. void sendChannelsDataOnLCD (void);
  68. void getNextSampleString (void);

  69. //char createdBy1 [] PROGMEM = {"Vassilis"};
  70. //char createdBy2 [] PROGMEM = {"Serasidis"};
  71. //char createdBy3 [] PROGMEM = {"(c)01 Jan 2012"};
  72. //char createdBy4 [] PROGMEM = {"www*serasidis*gr"};

  73. //========================================================================
  74. //  Main program
  75. //========================================================================
  76. int main(void)
  77. {       
  78.        
  79.         DDRD = 0x00;
  80.         PORTD = 0x00;

  81.         DDRC = 0x00;
  82.         PORTC = 0xff;

  83.         DDRB |= (1<<LED1);

  84.         PORTB &= ~(1<<LED1);
  85.         PORTD |= (1<<BTN_INCREASE);     //Enable pull-up resistor on BTN_DECREASE pin.
  86.         PORTC |= (1<<BTN_DECREASE);    //Enable pull-up resistor on BTN_INCREASE pin.
  87.         PORTD |= (1<<BTN_ZOOM_OUT); //Enable pull-up resistor on BTN_ZOOM_OUT pin.

  88.         _delay_ms(100);

  89.         lcd_init();

  90.         _delay_ms(100);

  91.         lcd_contrast(0x40);

  92.         printPictureOnLCD(introScreen);
  93.         printPictureOnLCD(createdBy);
  94.        
  95.         samplesPos = 0;
  96.         bufferUsedSpace = 0;
  97.         zoom = 1;
  98.         minSampleTime = MAX_SAMPLE_TIME;
  99.         counter = 0;

  100.         lcd_clear();
  101.         lcd_goto_xy(3,3);
  102.         lcd_str("Waiting for");
  103.         lcd_goto_xy(4,4);
  104.         lcd_str("signal...");
  105.        
  106.         checkInputs(); // Stay here until a logic level change will be made on PORT D.
  107.                        // Then, read all changes on PORT D until dataBuffer will be full.

  108.         lcd_clear();
  109.         lcd_goto_xy(14,1);
  110.         lcd_chr('1');
  111.         printRuler();
  112.         sendChannelsDataOnLCD();
  113.        
  114.         for(;;)
  115.         {
  116.                 checkDecreaseButton();
  117.                 checkIncreaseButton();
  118.                 checkIfNoButtonIsPressed();
  119.         }
  120. }


  121. //========================================================================
  122. //
  123. //========================================================================
  124. void getNextSampleString (void)
  125. {
  126.         unsigned int w;

  127.         if(bit_is_clear(PINC,BTN_DECREASE))
  128.         {
  129.                 for(w=0; w<BUFFER_SIZE;w++) //Clear the buffer for next sample string.
  130.                         dataBuffer[w] = 0xFF;

  131.                 samplesPos = 0;
  132.                 bufferUsedSpace = 0;
  133.                 zoom = 0;
  134.                 minSampleTime = MAX_SAMPLE_TIME;
  135.                 counter = 0;
  136.                
  137.                 lcd_clear();
  138.                 lcd_goto_xy(3,3);
  139.                 lcd_str("Waiting for");
  140.                 lcd_goto_xy(4,4);
  141.                 lcd_str("signal...");
  142.                 checkInputs();
  143.                 lcd_clear();
  144.                 lcd_goto_xy(14,1);
  145.                 lcd_chr('1');
  146.                 printRuler();
  147.         }
  148. }
  149. //========================================================================
  150. //
  151. //========================================================================
  152. void checkInputs (void)
  153. {

  154.         unsigned char dataPins;

  155.         dataPins = PIND; //Read the pins status on Port D (this is the initial PORT D status).

  156.         while (dataPins == PIND); //Stay here until at least one pin on PORT D changes its Logic status.

  157.         PORTB |= (1<<LED1); //Turn-ON the LED. Start recording sample lengths to the AVR's dataBuffer.
  158.         while(bufferUsedSpace < BUFFER_SIZE) //While the used buffer is not full, repeat this loop.
  159.         {
  160.                 if((dataPins == PIND)&&(counter < MAX_SAMPLE_TIME)) // If the PORT D has the same status as before, just...
  161.                         counter++;                                                                                //... increase the counter.
  162.                 else  // or else,
  163.                 {       
  164.                         saveSampleToBuffer(); //save to the buffer the length of the pulse.
  165.                         dataPins = PIND;      //Read the pins status on Port D.
  166.                 }       
  167.         }
  168.         PORTB &= ~(1<<LED1); //Turn-OFF the LED. That means that AVR has filled its dataBuffer.
  169. }
  170. //========================================================================
  171. //
  172. //========================================================================
  173. void checkIfNoButtonIsPressed (void)
  174. {
  175.         unsigned int w;

  176.         if(bit_is_clear(PIND,BTN_ZOOM_OUT))
  177.         {
  178.                 while(bit_is_clear(PIND,BTN_ZOOM_OUT));
  179.                         getNextSampleString();
  180.                 if((zoom > 0)&&(zoom < 8192))
  181.                         zoom *= 2;
  182.                 else
  183.                         zoom = 1;
  184.                
  185.                 lcd_clear_area(1,61,83);
  186.                 itoa(zoom,int2str,10);
  187.                 w = strlen(int2str);
  188.                 lcd_goto_xy(15 - w,1);
  189.                 lcd_str(int2str);

  190.                 sendChannelsDataOnLCD();
  191.         }
  192. }

  193. //========================================================================
  194. //
  195. //========================================================================
  196. void checkIncreaseButton (void)
  197. {
  198.         if(bit_is_clear(PIND,BTN_INCREASE)&&(samplesPos < POSITIONS_LENGTH)) //Scroll to the left the waveform content.
  199.         {

  200.                 if(counter < MAX_SAMPLE_TIME)
  201.                 {
  202.                         if(samplesPos < (POSITIONS_LENGTH - zoom))
  203.                                 samplesPos += zoom;
  204.                         sendChannelsDataOnLCD();
  205.                 }
  206.         }
  207. }               

  208. //========================================================================
  209. //
  210. //========================================================================
  211. void checkDecreaseButton (void)
  212. {
  213.         if(bit_is_clear(PINC,BTN_DECREASE)&&(samplesPos > 0)) //Scroll to the right the waveform content.
  214.         {
  215.                 if(counter < MAX_SAMPLE_TIME)
  216.                 {
  217.                         if(samplesPos >= zoom)
  218.                                 samplesPos -= zoom;
  219.                         sendChannelsDataOnLCD();
  220.                 }
  221.         }
  222. }

  223. //========================================================================
  224. //
  225. //========================================================================
  226. void printCapturedData (unsigned long position, unsigned char inputChannel)
  227. {
  228.         unsigned int m,j, b,sampleLength,n,samplLength;
  229.         unsigned char w, sample, nextSample = 0;
  230.         unsigned long lengthSum,oldLength;

  231.         lcd_clear_area(1,1,42);

  232.         ltoa(position,int2str,10);
  233.         w = strlen(int2str);
  234.         lcd_goto_xy(9-w,1);
  235.         lcd_str(int2str);
  236.         lcd_goto_xy(1,inputChannel + 3); //Go to LCD line 3, 4, 5 or 6.

  237.         n = 0;
  238.         w = 1;
  239.         b = 0;
  240.         lengthSum = 0;
  241.         oldLength = 0;
  242.         samplLength = 0;

  243.         sampleLength = dataBuffer[b];
  244.         sampleLength <<= 8; //HIGH byte of counter
  245.         sampleLength |= dataBuffer[b+1]; //LOW byte of counter

  246.         do
  247.         {
  248.                 lengthSum += sampleLength;
  249.                 if(samplesPos > lengthSum)
  250.                 {
  251.                         oldLength += sampleLength;
  252.                         b += 3; //Each sample has 3 bytes. 2 for sample length and 1 for the PIN D status data.
  253.                         sampleLength = dataBuffer[b];
  254.                         sampleLength <<= 8; //HIGH byte of counter
  255.                         sampleLength |= dataBuffer[b+1]; //LOW byte of counter
  256.                 }
  257.         }while(samplesPos > lengthSum);

  258.         for(m=b;m<BUFFER_SIZE;m+=3)
  259.         {
  260.                 sampleLength = dataBuffer[m];
  261.                 sampleLength <<= 8; //HIGH byte of counter
  262.                 sampleLength |= dataBuffer[m+1]; //LOW byte of counter

  263.                 if(w > 0)
  264.                 {
  265.                         sampleLength -= (samplesPos - oldLength);
  266.                         w=0;                       
  267.                 }
  268.                
  269.                 sample = dataBuffer[m+2];
  270.                 if((m+5) < BUFFER_SIZE)
  271.                 {
  272.                         nextSample = dataBuffer[m+5];
  273.                         nextSample ^= sample;
  274.                 }
  275.                 samplLength = sampleLength;
  276.                 if(zoom > 0)
  277.                         samplLength /= zoom;

  278.                 for(j=0;j<samplLength;j++)
  279.                 {
  280.                         if(bit_is_set(sample,inputChannel))
  281.                                 lcd_col(ONE); //1
  282.                         else
  283.                                 lcd_col(ZERO);//0
  284.                         n++;

  285.                         if(n >= ONE_LINE_LENGTH)
  286.                                 break;
  287.                 }
  288.                 if(bit_is_set(nextSample,inputChannel))
  289.                 {
  290.                                 lcd_pixelBack();
  291.                                 lcd_col(TRANSITION);
  292.                                 nextSample = 0; //Set nextSample to <No Sample> status.
  293.                 }

  294.                 if(n >= ONE_LINE_LENGTH)
  295.                         break;
  296.         }
  297. }


  298. //========================================================================
  299. //
  300. //========================================================================
  301. void printRuler (void)
  302. {
  303.         unsigned char k;

  304.         lcd_goto_xy(1,2); //Go to LCD line 2.

  305.         for(k=0;k<8;k++)
  306.         {
  307.                 lcd_col(TRANSITION);
  308.                 lcd_col(0b00000000);
  309.                 lcd_col(0b00011000);
  310.                 lcd_col(0b00000000);
  311.                 lcd_col(0b00011000);
  312.                 lcd_col(0b00000000);
  313.                 lcd_col(0b00011000);
  314.                 lcd_col(0b00000000);
  315.                 lcd_col(0b00011000);
  316.                 lcd_col(0b00000000);
  317.         }
  318.         lcd_col(TRANSITION);
  319.         lcd_col(0b00000000);
  320.         lcd_col(0b00011000);
  321.         lcd_col(0b00000000);
  322. }

  323. //========================================================================
  324. //
  325. //========================================================================
  326. void saveSampleToBuffer (void)
  327. {
  328. ……………………

  329. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼


所有資料51hei提供下載:

miniLogicAnalyzer.rar (1.2 MB, 下載次數(shù): 39)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:56204 發(fā)表于 2018-10-25 06:07 來自手機 | 只看該作者
一直想做個測試儀,這個很好下載
回復(fù)

使用道具 舉報

板凳
ID:51443 發(fā)表于 2018-10-25 18:23 | 只看該作者
本帖最后由 職教電子 于 2018-11-3 17:22 編輯

原來沒看出來用的是啥開發(fā)環(huán)境
回復(fù)

使用道具 舉報

地板
ID:51443 發(fā)表于 2018-11-7 12:15 | 只看該作者
不知道這個如果要改用progisp下載程序,熔絲位該怎樣設(shè)置?
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 天天操夜夜爽 | 亚洲精品二区 | 欧美一级黄色免费看 | 午夜视频在线免费观看 | 天天玩天天操天天干 | 亚洲五码在线 | 中文字幕人成乱码在线观看 | 久久久美女 | 欧美一区二区三 | 毛片毛片毛片毛片 | 精品国产乱码久久久久久闺蜜 | 一区二区三区在线播放 | 久久国产精品免费一区二区三区 | www.成人.com| 成人国产一区二区三区精品麻豆 | 亚洲精品久久久久久久久久久久久 | 日韩精品免费 | 久在线视频 | 成人免费观看视频 | 久久久影院 | 国产精品一区二 | 久久精品视频一区二区 | 91精品国产综合久久婷婷香蕉 | 国产成人99久久亚洲综合精品 | 国产成人午夜电影网 | 国产一二三区免费视频 | 成人在线视频网 | 国产日产精品一区二区三区四区 | 免费视频一区二区 | 91精品一区| 亚洲精品国产成人 | 欧美一级大黄 | 欧美日韩高清在线一区 | 麻豆av网站 | 日韩成人免费视频 | 北条麻妃国产九九九精品小说 | 国产成人在线免费 | 亚洲一区二区三区视频在线 | 日本久久综合网 | 久久久国产一区二区三区 | 成人影院午夜 |