# Keil uVision

## Criando um projeto

Acesse o menu ***Project->New uVision Project***. Em seguida, indique um diretório e o nome do projeto.

Na lista de dispositivos, selecione o fabricante NXP. Em seguida, selecione a família KL2x e o dispositivo que será utilizado: MKL25Zxxx4.

![](/files/-LKmK2uvNm50J_S8zY4X)

Na próxima tela são exibidas algumas configurações que podem ser adicionadas no projeto. Para esse exemplo, selecione os arquivos de inicialização e a biblioteca [CMSIS](http://www.keil.com/pack/doc/CMSIS/Core/html/index.html).

![](/files/-LKmKeeNZFi608UQgAm1)

## Arquivos de código e Estrutura do Projeto

Devido a configuração realizada na etapa inicial, o projeto apresenta 3 arquivos:

* [startup\_MKL25Z4.s](http://www.keil.com/pack/doc/CMSIS/Core/html/startup_s_pg.html): arquivo de inicialização que contém a definição dos vetores de interrupção, reset handler, regiões de stack e heap, entre outros;
* [system\_MKL25Z4.c](http://www.keil.com/pack/doc/CMSIS/Core/html/system_c_pg.html): arquivo de configuração do sistema de clock conforme opções indicadas no pré-processador. Define a função SystemInit que é chamada no ResetHandler;
* [system\_MKL25Z4.h](http://www.keil.com/pack/doc/CMSIS/Core/html/system_c_pg.html): Define a assinatura das funções SystemInit e SystemCoreClockUpdate.

![](/files/-LKmSShgf3N-yjOWo7iK)

No painel de controle do projeto, selecione o diretório ***Source Group 1*** e adicione um novo item ao projeto.

![](/files/-LKmUDz01vdLRwMQw-6f)

Em seguida, selecione a opção C File e indique o nome do arquivo.

![](/files/-LKmTzpTyTvLHMGmujyI)

A estrutura do projeto é ilustrada na Figura abaixo.

![CMSIS-Core Device Templates: http://www.keil.com/pack/doc/CMSIS/Core/html/templates\_pg.html](/files/-LKmvjhRZfRr7AB7G-12)

## Programa principal e Compilação

Adicione a função principal e compile o projeto.

```c
int main()
{
	//configurações iniciais
	
	while(1){
			//programa em loop infinito
	}
}
```

Na janela ***Build Output***, observe as etapas de [compilação do projeto](https://bit-by-bit.gitbook.io/embedded-systems/programacao/compilacao). Note que os arquivos são compilados individualmente e no final a ferramenta de Link é utilizada para criar a imagem do programa.

![](/files/-LKmhDZ7RhOStpudQdYl)

## Interface de comunicação

### Seleção da ferramenta de Debug

Acesse as opções de configuração do projeto.

![](/files/-LKmlYinmIGNp2H0N6wl)

No item ***Debug***, selecione a ferramenta ***PEMicro***.

![](/files/-LKmbIfABc9ev04mQgLQ)

### Configuração da Sessão de Debug

Para entrar no modo ***Debug***, acesse o menu ***Debug->Start Debug***.

![](/files/-LKmk4fovBfIMLH8_N2C)

Para configuração da ferramenta de ***Debug***, selecione a opção ***Open SDA em Interface***.

![](/files/-LKmkt5y47P8tC8gQWQL)

Em seguida, indique o microcontrolador em ***Select New Device***.

![](/files/-LKml7u653Aj1lAQxi8h)

Por fim, pressione o botão ***Connect***.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bit-by-bit.gitbook.io/embedded-systems/freedom-board-kl25z/programacao/keil-uvision.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
