4주차

배재영·2021년 5월 24일
0

자율주행 S/W 교육

목록 보기
4/7
post-thumbnail

디바이스에 달력과 날짜 화면 띄우기

#include <stdio.h>
#include "2450addr.h"
#include "my_lib.h"
#include "macro.h"
#include "option.h"

void MMU_Init(void);

// 아이콘 그림들의 지정
#include "./button/RUN_ER.H"
#include "./button/RUN_EP.H"

// 불러올 그래픽 화일을 지정
#include "./Images/CALBACK2.h"
#include "./Images/DROGBA.h"
#include "./Images/WINDOW.h"

// Color Define
// [D15-D11]RED, [D10-D6]GREEN, [D5-D1]BLUE
#define BLACK	0x0000
#define WHITE		0xfffe
#define BLUE		0x003e
#define GREEN	0x07c0
#define RED		0xf800
#define YELLOW	0xffc0
#define SKY_BLUE 0x5fff

// ISR Functions declaration

#define LCD_XSIZE 		(480)	
#define LCD_YSIZE 		(272)

extern unsigned int HandleTIMER0;
extern unsigned int HandleUART1;

// Functions Declaration

void HW_Initial(void);
void Show_Welcome(char * msg);
void Display_Rtc(void);
void Rtc_TimeSet(void);
void Display_Rtc_After(int a);
int Key_Get_Pressed(void);
void Key_ISR(void);
void Key_Port_Init(void);
void Key_INT_Init(void);
int Key_Get_Pressed(void);
int Key_Wait_Get_Pressed(void);
void Key_Wait_Get_Released(void);

// Global Variables Declaration

// 터치패드가 눌림을 알수 있는 값
volatile int Touch_pressed = 0;
// ADC 값
volatile int ADC_x=0, ADC_y=0;

// Calibration 정보 저장 값
volatile int Cal_x1=848;
volatile int Cal_y1=656;
volatile int Cal_x2=186;
volatile int Cal_y2=349; 

// 좌표 변환 값
volatile int Touch_x, Touch_y;
// Calibration 완료 값
volatile unsigned int Touch_config=1;

int xtmp, ytmp;

void Touch_ISR(void) __attribute__ ((interrupt ("IRQ")));

void Touch_ISR()
{
	/*
	Do not this code
	rINTSUBMSK |= (0x1<<9);
	rINTMSK1 |= (0x1<<31);	
	*/
	
	/* TO DO: Pendng Clear on Touch */	
	rSUBSRCPND |= (0x1<<9);
	rSRCPND1 |= (0x1<<31);
	rINTPND1 |= (0x1<<31);
	 
	// Touch UP
	if(rADCTSC&0x100)
	{
		rADCTSC&=0xff;
		Touch_pressed = 0;
	}
	// Touch Down
	else 
	{
		rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
		/* 
		(0<<8)손가락 터치하는 순간 이벤트 발생
		...
		*/
		// SADC_ylus Down,Don't care,Don't care,Don't care,Don't care,XP pullup Dis,Auto,No operation
		rADCCON|=0x1; /* start! */
		while(rADCCON & 0x1);
		while(!(0x8000&rADCCON)); 
		/* 15bit check */
		ADC_x=(int)(0x3ff&rADCDAT0);
		ADC_y=(int)(0x3ff&rADCDAT1);
		// 10bit 만큼만 마스킹
		// Touch calibration complete
		if(Touch_config)
		{
			Touch_y=(ADC_y-Cal_y1)*(LCD_YSIZE-10)/(Cal_y2-Cal_y1)+5;
			Touch_x=(ADC_x-Cal_x2)*(LCD_XSIZE-10)/(Cal_x1-Cal_x2)+5;
			Touch_x=LCD_XSIZE-Touch_x;
			if(Touch_x<0) Touch_x=0;
			if(Touch_x>=LCD_XSIZE) Touch_x=LCD_XSIZE-1;
			if(Touch_y<0) Touch_y=0;
			if(Touch_y>=LCD_YSIZE) Touch_y=LCD_YSIZE-1;
		}
		// before calibration		
		else
		{
			Touch_x = ADC_x;
			Touch_y = ADC_y;
		}

		rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
		// SADC_ylus Up,Don't care,Don't care,Don't care,Don't care,XP pullup En,Normal,Waiting mode
		Touch_pressed = 1; 
	}

/*	rINTSUBMSK &= ~(0x1<<9);
	rINTMSK1 &= ~(0x1<<31);*/
}
// Lower Layer Functions

void HW_Initial(void)
{
	// 필요한 초기화 루틴들을 기입한다
	Exception_Init();
	Uart_Init(115200);	
//	Led_Init();
//	Buzzer_Init();

	Timer0_Init();
	Graphic_Init();
	
	Touch_Isr_Init(Touch_ISR);
	MMU_Init();
}

void Show_Welcome(char * msg)
{
	int a, j; 
	
	Uart_Printf("\n%s\n", msg);
	
	for(a=0;a<2;a++)
	{
		Led_Display(7);
		for(j=0; j<0x0ffff; j++);
		Led_Display(0);
		for(j=0; j<0x0ffff; j++);
	}
}

void Lcd_Show(char *image)
{
	Lcd_Clr_Screen(BLACK);
	Lcd_Select_Frame_Buffer(0);
	Lcd_Get_Info_BMP(&xtmp, &ytmp, image);
	Lcd_Draw_BMP(((LCD_XSIZE/2)-(xtmp/2)), ((LCD_YSIZE/2)-(ytmp/2)), image); 	
}

void main(void)
{
	int keyval;
	char* myPtr;

	Uart_Init(115200);

	HW_Initial();

/* malloc test */
	myPtr= malloc(4096);
	*myPtr= 'W';
/* printf test */
	printf("c=%c\n", *myPtr);
	free(myPtr);

	Lcd_Show(CALBACK2);
	Lcd_Printf(80,25, BLACK, SKY_BLUE,1,1,"현재 날짜와 시간을 터미널에 입력하세요");
	Key_Port_Init();

/* RTC test */
	Rtc_TimeSet();
	Lcd_Show(WINDOW);		
	Display_Rtc();
	Lcd_Printf(125,10, WHITE, BLACK,1,1,"Switch를 눌러 날짜를 변경하세요");
	Lcd_Printf(50,25, WHITE, BLACK,1,1,"SW4(년+) SW5(월+) SW6(일+) SW7(시+) SW8(분+)");
	Lcd_Printf(50,40, WHITE, BLACK,1,1,"SW9(년-) SW10(월-) SW11(일-) SW12(시-) SW13(분-)");	
	while(!Uart_Get_Pressed())
	{
		Key_Wait_Get_Pressed();		 
		keyval = Key_Wait_Get_Pressed();
		Key_Wait_Get_Released();

		switch(keyval)
		{
			case 1 : 
			{
				Uart_Printf("\ncase1 select!\n");
				Display_Rtc_After(1);
				break;
			}
			case 2 : 
			{
				Uart_Printf("\ncase2 select!\n");
				Display_Rtc_After(2);
				break;
			}			
			case 3 : 			
			{
				Uart_Printf("\ncase3 select!\n");
				Display_Rtc_After(3);
				break;
			}
			case 4 : 			
			{
				Uart_Printf("\ncase4 select!\n");
				Display_Rtc_After(4);
				break;
			}
			case 5 : 			
			{
				Uart_Printf("\ncase5 select!\n");
				Display_Rtc_After(5);
				break;
			}
			case 6 : 			
			{
				Uart_Printf("\ncase6 select!\n");
				Display_Rtc_After(6);
				break;
			}
			case 7 : 			
			{
				Uart_Printf("\ncase7 select!\n");
				Display_Rtc_After(7);
				break;
			}
			case 8 : 			
			{
				Uart_Printf("\ncase8 select!\n");
				Display_Rtc_After(8);
				break;
			}
			case 9 : 			
			{
				Uart_Printf("\ncase9 select!\n");
				Display_Rtc_After(9);
				break;
			}
			case 10 : 			
			{
				Uart_Printf("\ncase10 select!\n");
				Display_Rtc_After(10);
				break;
			}		
		}	
	}
	Uart_Printf("The End");
}
	
profile
Automotive programer

0개의 댓글