佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 4243|回复: 8

PIC MCU programming 提问 (显示图像在VGA Monitor 上)

[复制链接]
发表于 17-10-2010 11:47 AM | 显示全部楼层 |阅读模式
本帖最后由 pic 于 7-11-2010 03:32 PM 编辑

大家好,我有一些基本的programming疑问要请大家帮帮忙。

1。应用:用MCU通过VGA来显示一些图案在电脑荧幕上。应该会用PIC24HJ64GP204,如果各位有更好的提议请指点)
2。用途:想加强对MCU和assembly code的认识。

3。需要效果 :在电脑荧幕上显示一个四方形。
4。遇到的问题:Assembly Code全还给老师了。
5。经过什么试验/检查 :-

6. 电路图 :基本上没什么问题,只是连接RGB和hsync,vsync去电脑荧幕罢了。
7。 对于问题的头绪/见解:少壮不努力,老大徒伤悲。

8。对于问题需要的解决方案:
我用movlw b'00000011' 去 w,要如何把MSB的‘0’从W显示去RA0?
让后我必须要再显示下一个‘0’去RA0,想到的是用retlw把下一个‘0’拉上来再用同样的instruction(如果有人教的话)来显示就行了。

之前读了很多关于VGA的文档了,没想到要写assembly code的时候全无头绪。以前在读书是学过点PIC16F877a的皮毛。
请大家指点指点,谢谢。

9。资金/资源 -

评分

参与人数 1积分 +15 收起 理由
pic + 15 按版规发帖, 奖励。

查看全部评分

回复

使用道具 举报


ADVERTISEMENT

发表于 6-11-2010 09:25 AM | 显示全部楼层
大家好,我有一些基本的programming疑问要请大家帮帮忙。
1。应用:用MCU通过VGA来显示一些图案在电脑荧幕上。应该会用PIC24HJ64GP204,如果各位有更好的提议请指点)

简单的图案, 一些18F 可能都够了。
要复杂的图案, PIC32 可能都未必够快。。

2。用途:想加强对MCU和assembly code的认识。

没有人写ASM 用在PIC24HJ64GP204
都是用C code

3。需要效果 :在电脑荧幕上显示一个四方形。

可以的

4。遇到的问题:Assembly Code全还给老师了。

现在是用C 了, ASM 鲜少人用了。


6. 电路图 :基本上没什么问题,只是连接RGB和hsync,vsync去电脑荧幕罢了。

需要DAC。

7。 对于问题的头绪/见解:少壮不努力,老大徒伤悲。

google : PIC Pong
用人用16F84 做 电视游戏

http://www.rickard.gunee.com/projects/video/pic/pong.php
http://dt.prohosting.com/pic/pong.html


用示波器的XY mode

http://blog.makezine.com/archive/2006/11/vectorbased_pong_on_an_os.html


8。对于问题需要的解决方案:
我用movlw b'00000011' 去 w,要如何把MSB的‘0’从W显示去RA0?
让后我必须要再显示下一个‘0’去RA0,想到的是用retlw把下一个‘0’拉上来再用同样的instruction(如果有人教的话)来显示就行了。

ASM 我不会。C 可以吗?

之前读了很多关于VGA的文档了,没想到要写assembly code的时候全无头绪。以前在读书是学过点PIC16F877a的皮毛。
请大家指点指点,谢谢。

时代进步了。。。MCU 都是用C了。
要不要考虑做其他的东西来学习?
可能做一些比“用MCU通过VGA来显示一些图案在电脑荧幕上” 来的实用的东西。
如果纯粹要学, 也可以通过Simulator 如Proteus。
回复

使用道具 举报

 楼主| 发表于 6-11-2010 12:11 PM | 显示全部楼层
简单的图案, 一些18F 可能都够了。
要复杂的图案, PIC32 可能都未必够快。。


没有人写ASM 用在PI ...
pic 发表于 6-11-2010 09:25 AM


谢谢版主,我找到了一个比较好的(也可以说是比较懒的)方法,就是用内附SSD1926的demo板AC164127-5来把SD Card里的jpeg图案显示在电脑荧光屏上。
Code是在Microchip Library里面找到:

#include"MainDemo.h"


#if defined(GFX_PICTAIL_V2) || defined (GFX_PICTAIL_V1)


#error
Error: This demo works only along with Graphics PicTail 3

#endif


// Configuration bits

#ifdefined(__dsPIC33F__) || defined(__PIC24H__)

_FOSCSEL(FNOSC_PRI);

_FOSC(FCKSM_CSECMD&OSCIOFNC_OFF &POSCMD_XT);

_FWDT(FWDTEN_OFF);

#elifdefined(__PIC32MX__)


#pragma config FPLLODIV = DIV_1, FPLLMUL =MUL_20, FPLLIDIV = DIV_2, FWDTEN = OFF, FCKSM = CSECME, FPBDIV = DIV_1


#pragma config OSCIOFNC = ON, POSCMOD = XT,FSOSCEN = ON, FNOSC = PRIPLL


#pragma config CP = OFF, BWP = OFF, PWP =OFF

#else


#if defined(__PIC24FJ256GB110__)

_CONFIG1(JTAGEN_OFF& GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)

_CONFIG2(0xF7FF &IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS &FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_OFF)


#endif


#if defined(__PIC24FJ256GA110__)

_CONFIG1(JTAGEN_OFF& GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)

_CONFIG2(IESO_OFF &FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL &IOL1WAY_OFF)


#endif


#if defined(__PIC24FJ128GA010__)

_CONFIG2(FNOSC_PRIPLL& POSCMOD_XT) // Primary XT OSC with PLL

_CONFIG1(JTAGEN_OFF& FWDTEN_OFF)
// JTAG off, watchdogtimer off


#endif


#if defined (__PIC24FJ256GB210__)

_CONFIG1( WDTPS_PS32768& FWPSA_PR128 & ALTVREF_ALTVREDIS & WINDIS_OFF & FWDTEN_OFF& ICS_PGx2 & GWRP_OFF & GCP_OFF & JTAGEN_OFF)

_CONFIG2( POSCMOD_HS& IOL1WAY_OFF & OSCIOFNC_OFF & OSCIOFNC_OFF & FCKSM_CSDCMD& FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF)

_CONFIG3( WPFP_WPFP255& SOSCSEL_SOSC & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS& WPEND_WPENDMEM)


#endif


#if defined (__PIC24FJ256DA210__)

_CONFIG1( WDTPS_PS32768& FWPSA_PR128 & ALTVREF_ALTVREDIS & WINDIS_OFF & FWDTEN_OFF& ICS_PGx2 & GWRP_OFF & GCP_OFF & JTAGEN_OFF)

_CONFIG2( POSCMOD_HS& IOL1WAY_OFF & OSCIOFNC_OFF & OSCIOFNC_OFF & FCKSM_CSDCMD& FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF)

_CONFIG3( WPFP_WPFP255& SOSCSEL_SOSC & WUTSEL_LEG & ALTPMP_ALTPMPEN & WPDIS_WPDIS &WPCFG_WPCFGDIS & WPEND_WPENDMEM)


#endif

#endif


int main (void)

{


#if defined(__dsPIC33F__) ||defined(__PIC24H__)



// Configure Oscillator to operate thedevice at 40Mhz


// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2


// Fosc= 8M*40(2*2)=80Mhz for 8M inputclock


PLLFBD = 38;
// M=40


CLKDIVbits.PLLPOST = 0;
// N1=2


CLKDIVbits.PLLPRE = 0;
// N2=2


OSCTUN = 0;
// Tune FRC oscillator, ifFRC is used



// Disable Watch Dog Timer



RCONbits.SWDTEN = 0;



// Clock switching to incorporate PLL


__builtin_write_OSCCONH(0x03);
// Initiate Clock Switch to Primary



// Oscillator with PLL (NOSC=0b011)


__builtin_write_OSCCONL(0x01);
// Start clock switching


while(OSCCONbits.COSC != 0b011);



// Wait for Clock switch to occur


// Wait for PLL to lock


while(OSCCONbits.LOCK != 1)


{ };



#elif defined(__PIC32MX__)


SYSTEMConfig(GetSystemClock(),SYS_CFG_ALL);


#ifdef MULTI_MEDIA_BOARD_DM00123



CPLDInitialize();


CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG);


CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL);


#endif


#endif



#if defined(__dsPIC33FJ128GP804__) ||defined(__PIC24HJ128GP504__)


AD1PCFGL = 0xffff;


#endif



InitGraph();
// Graphics



// Set YUV mode to display JPEG


JPEGSetYUV();



while(1)


{


FSInit();
// File system


SearchRec nextFile;


if(-1 != FindFirst("*.*",ATTR_ARCHIVE, &nextFile))


{


do


{


if(!JPEGPutImage(nextFile.filename))


{ }



DelayMs(2000);


} while(-1 !=FindNext(&nextFile));


}
//end of if


}

//end ofwhile



// Restore RGB mode


JPEGSetRGB();



return (-1);

}


问题是这个板是去LCD的,所以要把它改成VGA Port。
对于C我没什么头绪,我以前读书时只学过一点C++的皮毛罢了,版主有什么好的读物可以介绍介绍?
有什么比较经济的选择来吧c code export 去 MCU 里?

谢谢!
回复

使用道具 举报

发表于 6-11-2010 01:54 PM | 显示全部楼层
本帖最后由 pic 于 6-11-2010 01:55 PM 编辑
问题是这个板是去LCD的,所以要把它改成VGA Port。
对于C我没什么头绪,我以前读书时只学过一点C++的皮毛罢了,版主有什么好的读物可以介绍介绍?
有什么比较经济的选择来吧c code export 去 MCU 里?
feng337 发表于 6-11-2010 12:11 PM

你其实是要做一些东西显示在VGA 吧, 商业用途? 而不是要学什么ASM。

我不知道的你的程度到哪里, 只是随便建议。
你要更简单, 就是用VGA ChipSet。
如果嫌麻烦, 你可以去找ISA 的VGA card。
一个很单纯的Address, data line, 你只要把Data 写进Video RAM 里, 其他的事就交给VGA card 去做吧, 你也不用去管什么DAC 之类的。。

比如:

如果不是, 就请你说明你真正要做什么, 放心, 没有人要你的商业秘密的。
回复

使用道具 举报

 楼主| 发表于 7-11-2010 01:08 PM | 显示全部楼层
你其实是要做一些东西显示在VGA 吧, 商业用途? 而不是要学什么ASM。

我不知道的你的程度到哪里, 只 ...
pic 发表于 6-11-2010 01:54 PM



没有什么秘密啦,我平时有拍照的爱好,只是想把拍得好看的照片放在电脑荧光屏里罢了。
回复

使用道具 举报

发表于 7-11-2010 03:30 PM | 显示全部楼层
没有什么秘密啦,我平时有拍照的爱好,只是想把拍得好看的照片放在电脑荧光屏里罢了。
feng337 发表于 7-11-2010 01:08 PM

哦。。显示照片

3。需要效果 :在电脑荧幕上显示一个四方形。

在电脑荧幕上显示一个四方形, 和显示照片, 这个效果的落差也太大了。。

LCD电子相簿也很便宜了。。
一些RMVB palyer 之类的也能做到你要的效果 (显示在电视)

如果本着学习的态度, 那么, 用High pin count 的PIC18/24/32 + SD Card + VGA 卡,
就是能达到你的目的了。

现在就去研究如何Interface,把data 写进 VGA Card 的video RAM 吧。。
下面的网页, 可以帮你起步, 希望楼主认真的做, 然后回来分享。
http://tinyvga.com/
http://www.vintage-computer.com/vcforum/showthread.php?16386-z80-homebrew-interfacing-to-VGA-card

http://tinyvga.com/avr-isa-vga




http://tinyvga.com/avr-sdram-vga


回复

使用道具 举报

Follow Us
 楼主| 发表于 7-11-2010 09:41 PM | 显示全部楼层
哦。。显示照片


在电脑荧幕上显示一个四方形, 和显示照片, 这个效果的落差也太大了。。

LCD电 ...
pic 发表于 7-11-2010 03:30 PM


谢谢版主无私的分享与指教,让我获益良多。万分感激。
买一个不过瘾,要自己做一个才过瘾。
回复

使用道具 举报

发表于 15-11-2010 08:51 PM | 显示全部楼层
谢谢版主无私的分享与指教,让我获益良多。万分感激。
买一个不过瘾,要自己做一个才过瘾。
feng337 发表于 7-11-2010 09:41 PM


要用vga就有点难。
timing要很好, refresh rate, resolution, hsync, vsync都息息相关,要配合一下。

用parallel lcd.简单一点,方便。

http://www.crystalfontz.com/products/176220m/datasheets/1209/CFAF240320ET.pdf
http://www.bestelecs.com/index.php?main_page=product_info&cPath=1_3&products_id=19
回复

使用道具 举报


ADVERTISEMENT

发表于 5-3-2011 01:22 AM | 显示全部楼层

RE: PIC MCU programming 提问 (显示图像在VGA Monitor 上)

我个人用Turbo Pascal 7编写了320x200x256的GRAPHICS模块,兹给大家参考:
  1. unit Graphics;
  2. {
  3.   Graphical Interface Service Unit
  4.   Revision 1 (1998)
  5.   Developed by Boo Khan Ming

  6.   Provide bitmap manipulation options and simple graphics drawing in
  7.   320x200x256 graphics mode.
  8. }

  9. interface

  10. procedure PrepareGraphicsPage;
  11. procedure ClearGraphicsPage(Color:byte);
  12. procedure FlipHorizontal;
  13. procedure FlipVertical;
  14. procedure FillGraphicsPage(CompareColor,NewColor:byte);
  15. procedure InvertGraphicsPage;
  16. procedure BitwiseANDGraphicsPage(Value:byte);
  17. procedure BitwiseXORGraphicsPage(Value:byte);
  18. procedure BitwiseORGraphicsPage(Value:byte);
  19. procedure DrawPixel(X,Y:word;Color:byte);
  20. function ScanPixel(X,Y:word):byte;

  21. implementation

  22. uses Video;

  23. procedure PrepareGraphicsPage; assembler;
  24. asm
  25.   mov  ax, 0013h
  26.   int  10h
  27. end;

  28. procedure ClearGraphicsPage(Color:byte); assembler;
  29. asm
  30.   mov  ax, 0a000h
  31.   mov  es, ax
  32.   mov  cx, 32000
  33.   xor  di, di
  34.   mov  ah, Color
  35.   mov  al, Color
  36.   cld
  37.   repnz stosw
  38. end;

  39. procedure FlipHorizontal; assembler;
  40. var
  41.   Base:word;

  42. asm
  43.   push ds
  44.   mov  ax, 0a000h                { setting up all video segment and offset }
  45.   mov  es, ax
  46.   mov  ds, ax
  47.   xor  si, si
  48.   xor  di, di

  49.   mov  cx, 200                   { line counter }

  50. @page:
  51.   push cx
  52.   mov  ax, 200                   { compute current line number }
  53.   sub  ax, cx                    { in ascending order (200-CX) }
  54.   mov  dx, 320
  55.   mul  dx                        { compute actual memory offset (320*Y) }
  56.   mov  dx, ax
  57.   mov  Base, ax
  58.   add  dx, 318                   { point to current line's right most pixel }
  59.   mov  cx, 80                    { number of operation to run per line (320/4) }

  60. @line:
  61.   mov  ax, word ptr ds:[si]      { retrieve left most pixel }
  62.   push si
  63.   mov  bx, dx                    { keep original inverse offset }
  64.   sub  dx, si                    { compute new inverse offset }
  65.   mov  si, dx                    { inverse source offset }
  66.   add  si, Base                  { justify with current starting line number }
  67.   mov  dx, bx                    { restore original inverse offset }
  68.   mov  bx, word ptr ds:[si]      { retrieve right most pixel }
  69.   pop  si

  70.   xchg al, ah                   { swap two opponent pixels }
  71.   xchg bl, bh

  72.   add  si, 2                     { next pixel to retrieve }

  73.   mov  es:[di], bx               { store left most pixel }
  74.   push di
  75.   mov  bx, dx                    { keep original inverse offset }
  76.   sub  dx, di                    { compute new inverse offset }
  77.   mov  di, dx                    { inverse destination offset }
  78.   add  di, Base                  { justify with current starting line number }
  79.   mov  dx, bx                    { restore original inverse offset }
  80.   mov  es:[di], ax               { store right most pixel }
  81.   pop  di

  82.   add  di, 2                     { next pixel to store }

  83.   dec  cx
  84.   jne  @line
  85.   {loop @line}

  86.   add  si, 160                   { forward to next starting line }
  87.   add  di, 160

  88.   pop  cx
  89.   dec  cx
  90.   jne  @page                     { proceed to next line }
  91.   {loop @page}

  92.   pop  ds
  93. end;

  94. procedure FlipVertical; assembler;
  95. asm
  96.   push ds

  97.   mov  ax, 0a000h                { setting up all video segment and offset }
  98.   mov  es, ax
  99.   mov  ds, ax
  100.   xor  si, si
  101.   xor  di, di

  102.   mov  dx, 63680                 { last starting line }
  103.   mov  cx, 100                   { line counter (200/2) }

  104. @page:
  105.   push cx
  106.   mov  cx, 160                   { reduced half for faster 2-byte operation }

  107. @line:
  108.   mov  ax, word ptr ds:[si]      { retrieve upper line pixel }
  109.   push si
  110.   add  si, dx                    { point to lower part }
  111.   mov  bx, word ptr ds:[si]      { retrieve lower line pixel }
  112.   pop  si

  113.   add  si, 2

  114.   mov  es:[di], bx               { store inversed - lower to upper }
  115.   push di
  116.   add  di, dx                    { point to lower part }
  117.   mov  es:[di], ax               { store inversed - upper to lower }
  118.   pop  di

  119.   add  di, 2

  120.   dec  cx
  121.   jne  @line
  122.   {loop @line}

  123.   sub  dx, 640                   { lower part starting line (640-320=320) }

  124.   pop  cx
  125.   dec  cx
  126.   jne  @page
  127.   {loop @page}

  128.   pop  ds
  129. end;

  130. procedure FillGraphicsPage(CompareColor,NewColor:byte); assembler;
  131. asm
  132.   push es
  133.   push di

  134.   mov  ax, 0a000h
  135.   mov  es, ax
  136.   mov  cx, 64000
  137.   xor  di, di
  138.   mov  al, NewColor
  139.   mov  ah, NewColor

  140. @redo:
  141.   push cx
  142.   mov  bl, es:[di]
  143.   cmp  bl, CompareColor
  144.   jz   @fill
  145.   inc  di
  146.   pop  cx
  147.   dec  cx
  148.   jnz  @redo
  149.   jmp  @exit

  150. @fill:
  151.   stosb
  152.   pop  cx
  153.   dec  cx
  154.   jnz  @redo

  155. @exit:
  156.   pop  di
  157.   pop  es
  158. end;

  159. procedure InvertGraphicsPage; assembler;
  160. asm
  161.   push ds
  162.   mov  ax, 0a000h
  163.   mov  es, ax
  164.   mov  ds, ax
  165.   xor  di, di
  166.   xor  si, si
  167.   mov  cx, 32000

  168. @page:

  169.   mov  ax, word ptr ds:[si]
  170.   not  ax
  171.   mov  es:[di], ax

  172.   add  di, 2
  173.   add  si, 2

  174.   dec  cx
  175.   jne  @page

  176.   pop  ds
  177. end;

  178. procedure BitwiseANDGraphicsPage(Value:byte); assembler;
  179. asm
  180.   push ds
  181.   mov  ax, 0a000h
  182.   mov  es, ax
  183.   mov  ds, ax
  184.   xor  di, di
  185.   xor  si, si
  186.   mov  cx, 32000

  187. @page:

  188.   mov  ax, word ptr ds:[si]
  189.   and  ah, Value
  190.   and  al, Value
  191.   mov  es:[di], ax

  192.   add  di, 2
  193.   add  si, 2

  194.   dec  cx
  195.   jne  @page

  196.   pop  ds
  197. end;

  198. procedure BitwiseXORGraphicsPage(Value:byte); assembler;
  199. asm
  200.   push ds
  201.   mov  ax, 0a000h
  202.   mov  es, ax
  203.   mov  ds, ax
  204.   xor  di, di
  205.   xor  si, si
  206.   mov  cx, 32000

  207. @page:

  208.   mov  ax, word ptr ds:[si]
  209.   xor  ah, Value
  210.   xor  al, Value
  211.   mov  es:[di], ax

  212.   add  di, 2
  213.   add  si, 2

  214.   dec  cx
  215.   jne  @page

  216.   pop  ds
  217. end;

  218. procedure BitwiseORGraphicsPage(Value:byte); assembler;
  219. asm
  220.   push ds
  221.   mov  ax, 0a000h
  222.   mov  es, ax
  223.   mov  ds, ax
  224.   xor  di, di
  225.   xor  si, si
  226.   mov  cx, 32000

  227. @page:

  228.   mov  ax, word ptr ds:[si]
  229.   or   ah, Value
  230.   or   al, Value
  231.   mov  es:[di], ax

  232.   add  di, 2
  233.   add  si, 2

  234.   dec  cx
  235.   jne  @page

  236.   pop  ds
  237. end;

  238. procedure DrawPixel(X,Y:word;Color:byte); assembler;
  239. {
  240.   Mem[$A000:(Y*320)+X]:=Color;
  241. }
  242. asm
  243.   mov  ax, 0a000h
  244.   mov  es, ax
  245.   mov  bx, X
  246.   mov  ax, Y
  247.   mov  cl, 6
  248.   shl  ax, cl
  249.   add  bx, ax
  250.   mov  cl, 2
  251.   shl  ax, cl
  252.   add  bx, ax
  253.   mov  al, Color
  254.   mov  es:[bx], al
  255. end;

  256. function ScanPixel(X,Y:word):byte; assembler;
  257. {
  258.   Color:=Mem[$A000:(Y*320)+X];
  259. }
  260. asm
  261.   mov  ax, 0a000h
  262.   mov  es, ax
  263.   mov  bx, X
  264.   mov  ax, Y
  265.   mov  cl, 6
  266.   shl  ax, cl
  267.   add  bx, ax
  268.   mov  cl, 2
  269.   shl  ax, cl
  270.   add  bx, ax
  271.   mov  al, es:[bx]
  272. end;

  273. end.
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-4-2024 10:17 PM , Processed in 0.064090 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表