查看: 4415|回复: 8
|
PIC MCU programming 提问 (显示图像在VGA Monitor 上)
[复制链接]
|
|
本帖最后由 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。资金/资源 - |
评分
-
查看全部评分
|
|
|
|
|
|
|
发表于 6-11-2010 09:25 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 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
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 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 |
|
|
|
|
|
|
|
发表于 5-3-2011 01:22 AM
|
显示全部楼层
RE: PIC MCU programming 提问 (显示图像在VGA Monitor 上)
我个人用Turbo Pascal 7编写了320x200x256的GRAPHICS模块,兹给大家参考:
- unit Graphics;
- {
- Graphical Interface Service Unit
- Revision 1 (1998)
- Developed by Boo Khan Ming
- Provide bitmap manipulation options and simple graphics drawing in
- 320x200x256 graphics mode.
- }
- interface
- procedure PrepareGraphicsPage;
- procedure ClearGraphicsPage(Color:byte);
- procedure FlipHorizontal;
- procedure FlipVertical;
- procedure FillGraphicsPage(CompareColor,NewColor:byte);
- procedure InvertGraphicsPage;
- procedure BitwiseANDGraphicsPage(Value:byte);
- procedure BitwiseXORGraphicsPage(Value:byte);
- procedure BitwiseORGraphicsPage(Value:byte);
- procedure DrawPixel(X,Y:word;Color:byte);
- function ScanPixel(X,Y:word):byte;
- implementation
- uses Video;
- procedure PrepareGraphicsPage; assembler;
- asm
- mov ax, 0013h
- int 10h
- end;
- procedure ClearGraphicsPage(Color:byte); assembler;
- asm
- mov ax, 0a000h
- mov es, ax
- mov cx, 32000
- xor di, di
- mov ah, Color
- mov al, Color
- cld
- repnz stosw
- end;
- procedure FlipHorizontal; assembler;
- var
- Base:word;
- asm
- push ds
- mov ax, 0a000h { setting up all video segment and offset }
- mov es, ax
- mov ds, ax
- xor si, si
- xor di, di
- mov cx, 200 { line counter }
- @page:
- push cx
- mov ax, 200 { compute current line number }
- sub ax, cx { in ascending order (200-CX) }
- mov dx, 320
- mul dx { compute actual memory offset (320*Y) }
- mov dx, ax
- mov Base, ax
- add dx, 318 { point to current line's right most pixel }
- mov cx, 80 { number of operation to run per line (320/4) }
- @line:
- mov ax, word ptr ds:[si] { retrieve left most pixel }
- push si
- mov bx, dx { keep original inverse offset }
- sub dx, si { compute new inverse offset }
- mov si, dx { inverse source offset }
- add si, Base { justify with current starting line number }
- mov dx, bx { restore original inverse offset }
- mov bx, word ptr ds:[si] { retrieve right most pixel }
- pop si
- xchg al, ah { swap two opponent pixels }
- xchg bl, bh
- add si, 2 { next pixel to retrieve }
- mov es:[di], bx { store left most pixel }
- push di
- mov bx, dx { keep original inverse offset }
- sub dx, di { compute new inverse offset }
- mov di, dx { inverse destination offset }
- add di, Base { justify with current starting line number }
- mov dx, bx { restore original inverse offset }
- mov es:[di], ax { store right most pixel }
- pop di
- add di, 2 { next pixel to store }
- dec cx
- jne @line
- {loop @line}
- add si, 160 { forward to next starting line }
- add di, 160
- pop cx
- dec cx
- jne @page { proceed to next line }
- {loop @page}
- pop ds
- end;
- procedure FlipVertical; assembler;
- asm
- push ds
- mov ax, 0a000h { setting up all video segment and offset }
- mov es, ax
- mov ds, ax
- xor si, si
- xor di, di
- mov dx, 63680 { last starting line }
- mov cx, 100 { line counter (200/2) }
- @page:
- push cx
- mov cx, 160 { reduced half for faster 2-byte operation }
- @line:
- mov ax, word ptr ds:[si] { retrieve upper line pixel }
- push si
- add si, dx { point to lower part }
- mov bx, word ptr ds:[si] { retrieve lower line pixel }
- pop si
- add si, 2
- mov es:[di], bx { store inversed - lower to upper }
- push di
- add di, dx { point to lower part }
- mov es:[di], ax { store inversed - upper to lower }
- pop di
- add di, 2
- dec cx
- jne @line
- {loop @line}
- sub dx, 640 { lower part starting line (640-320=320) }
- pop cx
- dec cx
- jne @page
- {loop @page}
- pop ds
- end;
- procedure FillGraphicsPage(CompareColor,NewColor:byte); assembler;
- asm
- push es
- push di
- mov ax, 0a000h
- mov es, ax
- mov cx, 64000
- xor di, di
- mov al, NewColor
- mov ah, NewColor
- @redo:
- push cx
- mov bl, es:[di]
- cmp bl, CompareColor
- jz @fill
- inc di
- pop cx
- dec cx
- jnz @redo
- jmp @exit
- @fill:
- stosb
- pop cx
- dec cx
- jnz @redo
- @exit:
- pop di
- pop es
- end;
- procedure InvertGraphicsPage; assembler;
- asm
- push ds
- mov ax, 0a000h
- mov es, ax
- mov ds, ax
- xor di, di
- xor si, si
- mov cx, 32000
- @page:
- mov ax, word ptr ds:[si]
- not ax
- mov es:[di], ax
- add di, 2
- add si, 2
- dec cx
- jne @page
- pop ds
- end;
- procedure BitwiseANDGraphicsPage(Value:byte); assembler;
- asm
- push ds
- mov ax, 0a000h
- mov es, ax
- mov ds, ax
- xor di, di
- xor si, si
- mov cx, 32000
- @page:
- mov ax, word ptr ds:[si]
- and ah, Value
- and al, Value
- mov es:[di], ax
- add di, 2
- add si, 2
- dec cx
- jne @page
- pop ds
- end;
- procedure BitwiseXORGraphicsPage(Value:byte); assembler;
- asm
- push ds
- mov ax, 0a000h
- mov es, ax
- mov ds, ax
- xor di, di
- xor si, si
- mov cx, 32000
- @page:
- mov ax, word ptr ds:[si]
- xor ah, Value
- xor al, Value
- mov es:[di], ax
- add di, 2
- add si, 2
- dec cx
- jne @page
- pop ds
- end;
- procedure BitwiseORGraphicsPage(Value:byte); assembler;
- asm
- push ds
- mov ax, 0a000h
- mov es, ax
- mov ds, ax
- xor di, di
- xor si, si
- mov cx, 32000
- @page:
- mov ax, word ptr ds:[si]
- or ah, Value
- or al, Value
- mov es:[di], ax
- add di, 2
- add si, 2
- dec cx
- jne @page
- pop ds
- end;
- procedure DrawPixel(X,Y:word;Color:byte); assembler;
- {
- Mem[$A000:(Y*320)+X]:=Color;
- }
- asm
- mov ax, 0a000h
- mov es, ax
- mov bx, X
- mov ax, Y
- mov cl, 6
- shl ax, cl
- add bx, ax
- mov cl, 2
- shl ax, cl
- add bx, ax
- mov al, Color
- mov es:[bx], al
- end;
- function ScanPixel(X,Y:word):byte; assembler;
- {
- Color:=Mem[$A000:(Y*320)+X];
- }
- asm
- mov ax, 0a000h
- mov es, ax
- mov bx, X
- mov ax, Y
- mov cl, 6
- shl ax, cl
- add bx, ax
- mov cl, 2
- shl ax, cl
- add bx, ax
- mov al, es:[bx]
- end;
- end.
复制代码 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|