RS232와 422 488에 대한 설명
문자 처리.
문자열 처리.
하이퍼터미널로 받은값 처리.
CGRAM 사용으로 사용자 정의문자 처리.
SI로 컴파일..
전부 하나하나 함수이기때문에 갔따 쓰면된다.. 알아서 잘배끼라 ..!!
#include "project.h"
#include "AT91SAM7S256.h"
//#define _StringLCD
//#define _SerialLCD
#define _UserMode
#define PIN(num) AT91C_PIO_PA##num
#define MY_LOW (*(AT91_REG *)AT91C_PIOA_CODR)
#define MY_HIGH (*(AT91_REG *)AT91C_PIOA_SODR)
#define MY_RS PIN(8)
#define MY_RW PIN(11)
#define MY_ENB PIN(12)
#define MY_DB(num) PIN(num)
#define MAIN_OSC 18432000 // 크리스탈 속도
#define MAIN_CLK ((MAIN_OSC*73/14)/2) // 체배기를 거친 후 속도
#define DBGU_SPEED 115200 // 디버그 유닛 속도
void Reset_DBGU()
{
// Reset and disable receiver
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
// Disable interrupts
AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
// Configure PIOs for DBGU
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
AT91C_BASE_PIOA->PIO_BSR = 0;
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
// === Configure serial link ===
// Define the baud rate divisor register [BRGR = MAIN_CLK / (115200 * 16)]
AT91C_BASE_DBGU->DBGU_BRGR = MAIN_CLK / (DBGU_SPEED * 16);
// Define the USART mode
AT91C_BASE_DBGU->DBGU_MR = AT91C_US_PAR_NONE | AT91C_US_CHMODE_NORMAL;
// Disable the RX and TX PDC transfer requests
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS;
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_TXTDIS;
// Enable transmitter
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_TXEN | AT91C_US_RXEN;
}
unsigned char DBGU_Recv_Char()
{
while (0 == (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY));
return AT91C_BASE_DBGU->DBGU_RHR;
}
void init_LED()
{
(*(AT91_REG *)AT91C_PIOA_PER) = MY_DB(13)|MY_DB(29)|MY_DB(30);
(*(AT91_REG *)AT91C_PIOA_OER) = MY_DB(13)|MY_DB(29)|MY_DB(30);
MY_LOW = MY_DB(13)|MY_DB(30);
MY_HIGH = MY_DB(29);
}
void CharLCDEnable()
{
AT91C_BASE_PIOA->PIO_PER = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
AT91C_BASE_PIOA->PIO_OER = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
}
void Delay()
{
volatile unsigned int iCnt1;
for(iCnt1 = 0; iCnt1 < 10000 ; ++iCnt1);
}
void CharAllLOW()
{
MY_LOW = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
}
void Start()
{
CharAllLOW();
MY_LOW = MY_RW;
Delay();
MY_HIGH = MY_ENB; //4
Delay();
}
void End()
{
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH = MY_ENB;
}
void ClearDisplay()
{
Start();
MY_HIGH = MY_DB(0);
End();
}
void DisplayOnOff()
{
Start();
MY_HIGH = MY_DB(2)|MY_DB(3);
End();
}
void CursorOrDisplayShift()
{
Start();
MY_HIGH =MY_DB(2)|MY_DB(3)|MY_DB(4);
End();
}
void FunctionSet()
{
Start();
MY_HIGH = MY_DB(2)|MY_DB(3)|MY_DB(4)|MY_DB(5);
End();
}
void EntryMode()
{
Start();
MY_HIGH = MY_DB(1)|MY_DB(2);
End();
}
void SetLCD()
{
FunctionSet();
DisplayOnOff();
CursorOrDisplayShift();
EntryMode();
ClearDisplay();
}
void WriteDataRam(volatile unsigned char cData)
{
CharAllLOW();
MY_HIGH = MY_RS;
MY_HIGH = MY_ENB; //4
Delay();
MY_HIGH = cData;
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH =MY_RW;
Delay();
}
void SetDDRamAddr(volatile unsigned int iData)
{
Start();
MY_HIGH = MY_DB(7)|iData;
End();
}
void SetCGRamAddr(volatile unsigned int iData)
{
Start();
MY_HIGH = MY_DB(6)|iData;
End();
}
void StringLCD(volatile unsigned char * cData)
{
volatile unsigned int iCnt =0;
while(*(cData + iCnt) != 0)
{
CharAllLOW();
MY_HIGH = MY_RS;
MY_HIGH = MY_ENB; //4
Delay();
MY_HIGH = *(cData+iCnt);
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH =MY_RW;
Delay();
iCnt++;
}
}
void SerialLCD()
{
volatile unsigned char DD;
volatile unsigned int iCnt = 0;
Reset_DBGU();
while(1)
{
DD = DBGU_Recv_Char();
if(iCnt == 17)
{
SetDDRamAddr(0x40);
}
if(iCnt == 33)
{
ClearDisplay();
iCnt = 0;
}
WriteDataRam(DD);
iCnt++;
}
}
void UserMode()
{
volatile unsigned int iCnt;
volatile unsigned int font[] = {
0x0E, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x1F, 0x00,
0x09, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x09,
0x1E, 0x02, 0x02, 0x02, 0x1F, 0x04, 0x04, 0x04,
0x00, 0x00, 0x00, 0x15, 0x0A, 0x00, 0x00, 0x00};
SetCGRamAddr(0x40);
for(iCnt=0; iCnt <32; iCnt++)
{
WriteDataRam(font[iCnt]);
}
SetDDRamAddr(0x86);
WriteDataRam(0x00);
WriteDataRam(0x01);
WriteDataRam(0x02);
WriteDataRam(0x03);
}
int main()
{
init_LED(); // LED SETTING
CharLCDEnable(); // ALL LCD ENABLE
CharAllLOW(); // ALL DB LOW SETTING
SetLCD(); // LCD SETTING
#ifdef _StringLCD
StringLCD("ABCDEFG"); // STRING LCD
#endif
#ifdef _SerialLCD
SerialLCD(); // SERIAL LCD
#endif
#ifdef _UserMode
UserMode(); // USERMODE(KOREAN)
#endif
return 0;
}
내소스는 완벽하다 . 캠이 구린거다 ㅋㅋㅋ
그렇게 믿고 싶다 -_-
#include <windows.h>
#include "resource.h"
#include <Vfw.h>
//#define PIXELHISTO 1
//#define LINEHISTO 1
#define ALLHISTO 1
LRESULT CALLBACK FramInfo(HWND , LPVIDEOHDR);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DialogBoxProc(HWND,UINT,WPARAM,LPARAM);
void DrawBitmap(HDC, int, int, HBITMAP);
HINSTANCE g_hlnst;
LPCTSTR lpszClass=TEXT("WinCam");
HWND vfw;
HWND vfw2;
HWND Hwndmain;
int APIENTRY WinMain(HINSTANCE hlnstance,HINSTANCE hPrevlnstance,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hlnst=hlnstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hlnstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,
lpszClass,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
(HMENU)NULL,
hlnstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,NULL,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
BITMAPINFO bm;
PAINTSTRUCT ps;
HBITMAP hbit;
DWORD dwsize;
HBITMAP OldBitmap;
HANDLE hFile;
u_char buf1[280000];
DWORD dwWrite;
DWORD dwRead;
int Temp;
LPBYTE lpData1;
u_int Histo[3][256];
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
HDC hMemDC;
switch(iMessage)
{
case WM_CREATE:
hdc = GetDC(hWnd);
Hwndmain = hWnd;
vfw = capCreateCaptureWindow( TEXT("CAM")
,WS_CHILD | WS_VISIBLE
,0
,0
,500
,400
,hWnd
,0);
capDriverConnect(vfw, 0);
capPreviewRate(vfw, 1);
capPreview(vfw, TRUE);
capGetVideoFormat(vfw, &bm , sizeof(bm));
hbit = CreateCompatibleBitmap(hdc, bm.bmiHeader.biWidth, bm.bmiHeader.biHeight);
capSetCallbackOnFrame(vfw, FramInfo);
InvalidateRect(Hwndmain,NULL,TRUE);
ReleaseDC(hWnd, hdc);
return 0;
case WM_LBUTTONDOWN:
DialogBox(g_hlnst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DialogBoxProc);
return 0;
case WM_PAINT:
hdc = BeginPaint(Hwndmain, &ps);
hMemDC= CreateCompatibleDC(hdc);
DeleteDC(hMemDC);
EndPaint(Hwndmain, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK FramInfo(HWND vfw, LPVIDEOHDR VideoHdr)
{
HDC hMemDC;
HDC hdc;
HBITMAP OldBitmap;
int iCntX;
int iCntY;
int Jump=0;
int R, G, B;
WCHAR t[100];
HBRUSH Myblush;
HBRUSH Oldblush;
HPEN MyPen;
HPEN OldPen;
hdc = GetDC(Hwndmain);
hMemDC = CreateCompatibleDC(hdc);
OldBitmap = (HBITMAP)SelectObject(hMemDC,hbit);
Myblush = CreateSolidBrush(RGB(255,255,255));
Oldblush = (HBRUSH)SelectObject(hMemDC, Myblush);
memset(Histo, 0, sizeof(Histo));
for(iCntY= 0; iCntY < bm.bmiHeader.biHeight ; ++iCntY)
{
for(iCntX=0; iCntX < bm.bmiHeader.biWidth ; ++iCntX )
{
++Histo[0][(VideoHdr->lpData[Jump + 2])];
++Histo[1][(VideoHdr->lpData[Jump + 1])];
++Histo[2][(VideoHdr->lpData[Jump + 0])];
Jump += 3;
}
}
wsprintf(t, TEXT("%d"), Histo[0][0]+Histo[1][0]+Histo[2][0]);
SetWindowText(Hwndmain, t);
MyPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
OldPen = (HPEN)SelectObject(hMemDC, MyPen);
// RGB 히스토그램
Rectangle(hMemDC, 0, 0, 256 , bm.bmiHeader.biHeight);
for(iCntY= 0; iCntY < 255 ; ++iCntY)
{
#ifdef PIXELHISTO
// 점버전
SetPixel(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((((Histo[0][iCntY])+(Histo[1][iCntY])+(Histo[2][iCntY]))/15)/3), RGB(0,0,0));
#endif
#ifdef LINEHISTO
// 선버전
MoveToEx(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((((Histo[0][iCntY])+(Histo[1][iCntY])+(Histo[2][iCntY]))/15)/3), NULL);
LineTo(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((((Histo[0][iCntY+1])+(Histo[1][iCntY+1])+(Histo[2][iCntY+1]))/15)/3));
#endif
#ifdef ALLHISTO
// 면버전
MoveToEx(hMemDC,iCntY+1, bm.bmiHeader.biHeight - ((((Histo[0][iCntY])+(Histo[1][iCntY])+(Histo[2][iCntY]))/15)/3), NULL);
LineTo(hMemDC, iCntY+1, bm.bmiHeader.biHeight);
#endif
}
BitBlt(hdc, bm.bmiHeader.biWidth+30, 0, 256 , bm.bmiHeader.biHeight, hMemDC, 0, 0, SRCCOPY);
//RED값 히스토그램
MyPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
(HPEN)SelectObject(hMemDC, MyPen);
Rectangle(hMemDC, 0, 0, 256 , bm.bmiHeader.biHeight);
MyPen = CreatePen(PS_SOLID, 1, RGB(255,0,0));
(HPEN)SelectObject(hMemDC, MyPen);
for(iCntY= 0; iCntY < 255 ; ++iCntY)
{
#ifdef PIXELHISTO
// 점버전
SetPixel(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[0][iCntY])/15), RGB(0,0,0));
#endif
#ifdef LINEHISTO
// 선버전
MoveToEx(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[0][iCntY])/15), NULL);
LineTo(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[0][iCntY+1])/15));
#endif
#ifdef ALLHISTO
// 면버전
MoveToEx(hMemDC,iCntY, bm.bmiHeader.biHeight - ((Histo[0][iCntY])/15), NULL);
LineTo(hMemDC, iCntY, bm.bmiHeader.biHeight-1);
#endif
}
BitBlt(hdc, 2, bm.bmiHeader.biHeight+30, 256 , bm.bmiHeader.biHeight, hMemDC, 0, 0, SRCCOPY);
//GREEN값 히스토그램
MyPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
(HPEN)SelectObject(hMemDC, MyPen);
// Rectangle(hMemDC, 0, 0, 256 , bm.bmiHeader.biHeight);
MyPen = CreatePen(PS_SOLID, 1, RGB(0,255,0));
(HPEN)SelectObject(hMemDC, MyPen);
for(iCntY= 0; iCntY < 255 ; ++iCntY)
{
#ifdef PIXELHISTO
// 점버전
//SetPixel(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[1][iCntY])/15), RGB(0,0,0));
#endif
#ifdef LINEHISTO
// 선버전
MoveToEx(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[1][iCntY])/15), NULL);
LineTo(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[1][iCntY+1])/15));
#endif
#ifdef ALLHISTO
// 면버전
MoveToEx(hMemDC,iCntY, bm.bmiHeader.biHeight - ((Histo[1][iCntY])/15), NULL);
LineTo(hMemDC, iCntY, bm.bmiHeader.biHeight-1);
#endif
}
BitBlt(hdc, 256+10, bm.bmiHeader.biHeight+30, 256 , bm.bmiHeader.biHeight, hMemDC, 0, 0, SRCCOPY);
//BLUE값 히스토그램
MyPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
(HPEN)SelectObject(hMemDC, MyPen);
// Rectangle(hMemDC, 0, 0, 256 , bm.bmiHeader.biHeight);
MyPen = CreatePen(PS_SOLID, 1, RGB(0,0,255));
(HPEN)SelectObject(hMemDC, MyPen);
for(iCntY= 0; iCntY < 255 ; ++iCntY)
{
#ifdef PIXELHISTO
// 점버전
//SetPixel(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[2][iCntY])/15), RGB(0,0,0));
#endif
#ifdef LINEHISTO
// 선버전
MoveToEx(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[2][iCntY])/15), NULL);
LineTo(hMemDC, iCntY+25, bm.bmiHeader.biHeight - ((Histo[2][iCntY+1])/15));
#endif
#ifdef ALLHISTO
// 면버전
MoveToEx(hMemDC,iCntY, bm.bmiHeader.biHeight - ((Histo[2][iCntY])/15), NULL);
LineTo(hMemDC, iCntY, bm.bmiHeader.biHeight-1);
#endif
}
BitBlt(hdc, (256+10)<<1, bm.bmiHeader.biHeight+30, 256 , bm.bmiHeader.biHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, Oldblush);
DeleteObject(Myblush);
SelectObject(hMemDC, OldPen);
DeleteObject(MyPen);
SelectObject(hMemDC,OldBitmap);
DeleteDC(hMemDC);
ReleaseDC(Hwndmain,hdc);
return 0;
}
BOOL CALLBACK DialogBoxProc(HWND hDlg,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
TCHAR str[20] = {};
switch(iMessage)
{
case WM_COMMAND:
switch (wParam)
{
case IDOK:
GetDlgItemText(hDlg, IDC_EDIT1, str, sizeof(str));
capFileSaveDIB(vfw,str);
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}