Académique Documents
Professionnel Documents
Culture Documents
Project :
Version :
Date
: 28-Jun-2016
Author :
Company :
Comments:
Chip type
: ATxmega128A3U
Program type
: Application
: Small
: 2048
*******************************************************/
// Delay functions
#include <delay.h>
#include <stdio.h>
CLK_PSADIV_1_gc | CLK_PSBCDIV_1_1_gc;
CCP=CCP_IOREG_gc;
CLK.PSCTRL=n;
EVSYS.CH5CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 6 Digital Filter Coefficient: 1 Sample
EVSYS.CH6CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 7 Digital Filter Coefficient: 1 Sample
EVSYS.CH7CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Ports initialization
void ports_init(void)
{
// PORTA initialization
// OUT register
PORTA.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTA.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTA.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTA.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTA.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTA.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTA.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTA.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTA.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTA.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTA.INTCTRL=(PORTA.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// Pin5 Pin Change interrupt 0: Of
// Pin6 Pin Change interrupt 0: Of
// Pin7 Pin Change interrupt 0: Of
PORTA.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
// Pin2 Pin Change interrupt 1: Of
// Pin3 Pin Change interrupt 1: Of
// Pin4 Pin Change interrupt 1: Of
// Pin5 Pin Change interrupt 1: Of
// Pin6 Pin Change interrupt 1: Of
// Pin7 Pin Change interrupt 1: Of
PORTA.INT1MASK=0x00;
// PORTB initialization
// OUT register
PORTB.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTB.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTB.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTB.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTB.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTB.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTB.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTB.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTB.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTB.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTB.INTCTRL=(PORTB.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// PORTC initialization
// OUT register
PORTC.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTC.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTC.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTC.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTC.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTC.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTC.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTC.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTC.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTC.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// PORTC Peripheral Output Remapping
// OC0A Output: Pin 0
// OC0B Output: Pin 1
// OC0C Output: Pin 2
// OC0D Output: Pin 3
// USART0 XCK: Pin 1
// USART0 RXD: Pin 2
// USART0 TXD: Pin 3
// SPI MOSI: Pin 5
// SPI SCK: Pin 7
PORTC.REMAP=(0<<PORT_SPI_bp) | (0<<PORT_USART0_bp) | (0<<PORT_TC0D_bp)
| (0<<PORT_TC0C_bp) | (0<<PORT_TC0B_bp) | (0<<PORT_TC0A_bp);
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTC.INTCTRL=(PORTC.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// Pin5 Pin Change interrupt 0: Of
// Pin6 Pin Change interrupt 0: Of
// Pin7 Pin Change interrupt 0: Of
PORTC.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
// Pin2 Pin Change interrupt 1: Of
// Pin3 Pin Change interrupt 1: Of
// Pin4 Pin Change interrupt 1: Of
// Pin5 Pin Change interrupt 1: Of
// Pin6 Pin Change interrupt 1: Of
// Pin7 Pin Change interrupt 1: Of
PORTC.INT1MASK=0x00;
// PORTD initialization
// OUT register
PORTD.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTD.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTD.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTD.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTD.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTD.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTD.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTD.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTD.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTD.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTD.INTCTRL=(PORTD.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// Pin5 Pin Change interrupt 0: Of
// Pin6 Pin Change interrupt 0: Of
// Pin7 Pin Change interrupt 0: Of
PORTD.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
// Pin2 Pin Change interrupt 1: Of
// Pin3 Pin Change interrupt 1: Of
// Pin4 Pin Change interrupt 1: Of
// Pin5 Pin Change interrupt 1: Of
// Pin6 Pin Change interrupt 1: Of
// Pin7 Pin Change interrupt 1: Of
PORTD.INT1MASK=0x00;
// PORTE initialization
// OUT register
PORTE.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTE.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTE.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTE.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTE.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTE.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTE.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTE.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTE.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTE.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTE.INTCTRL=(PORTE.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// Pin5 Pin Change interrupt 0: Of
// Pin6 Pin Change interrupt 0: Of
// Pin7 Pin Change interrupt 0: Of
PORTE.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
// Pin2 Pin Change interrupt 1: Of
// Pin3 Pin Change interrupt 1: Of
// Pin4 Pin Change interrupt 1: Of
// Pin5 Pin Change interrupt 1: Of
// Pin6 Pin Change interrupt 1: Of
// Pin7 Pin Change interrupt 1: Of
PORTE.INT1MASK=0x00;
// PORTF initialization
// OUT register
PORTF.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTF.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTF.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTF.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Of
// Pin2 Slew Rate Limitation: Of
PORTF.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Of
// Pin3 Slew Rate Limitation: Of
PORTF.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Of
// Pin4 Slew Rate Limitation: Of
PORTF.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Of
// Pin5 Slew Rate Limitation: Of
PORTF.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Of
// Pin6 Slew Rate Limitation: Of
PORTF.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Of
// Pin7 Slew Rate Limitation: Of
PORTF.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTF.INTCTRL=(PORTF.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
// Pin2 Pin Change interrupt 0: Of
// Pin3 Pin Change interrupt 0: Of
// Pin4 Pin Change interrupt 0: Of
// Pin5 Pin Change interrupt 0: Of
// Pin6 Pin Change interrupt 0: Of
// Pin7 Pin Change interrupt 0: Of
PORTF.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
// Pin2 Pin Change interrupt 1: Of
// Pin3 Pin Change interrupt 1: Of
// Pin4 Pin Change interrupt 1: Of
// Pin5 Pin Change interrupt 1: Of
// Pin6 Pin Change interrupt 1: Of
// Pin7 Pin Change interrupt 1: Of
PORTF.INT1MASK=0x00;
// PORTR initialization
// OUT register
PORTR.OUT=0x00;
// Pin0: Input
// Pin1: Input
PORTR.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Of
// Pin0 Slew Rate Limitation: Of
PORTR.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Of
// Pin1 Slew Rate Limitation: Of
PORTR.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTR.INTCTRL=(PORTR.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Of
// Pin1 Pin Change interrupt 0: Of
PORTR.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Of
// Pin1 Pin Change interrupt 1: Of
PORTR.INT1MASK=0x00;
}
// ADCA initialization
void adca_init(void)
{
// ADCA is enabled
// Resolution: 8 Bits
// Free Running mode: Of
// Gain stage impedance mode: High-impedance sources
// Current consumption: No limit
// Conversion mode: Unsigned
ADCA.CTRLB=(0<<ADC_IMPMODE_bp) | ADC_CURRLIMIT_NO_gc |
(0<<ADC_CONMODE_bp) | ADC_RESOLUTION_8BIT_gc;
void main(void)
{
// Declare your local variables here
unsigned char n;
// The interrupt vectors will be placed at the start of the Application FLASH section
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm |
PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)));
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
// Set the default priority for round-robin scheduling
PMIC.INTPRI=0x00;
// Restore optimization for size if needed
#pragma optsize_default
// Ports initialization
ports_init();
// ADCA initialization
adca_init();
// EN - PORTC Pin 2
// D4 - PORTC Pin 4
// D5 - PORTC Pin 5
// D6 - PORTC Pin 6
// D7 - PORTC Pin 7
// Characters/line: 16
lcd_init(16);
while (1)
{
// Place your code here
lcd_clear();
a=adca_read(1);
lcd_gotoxy(0,0);
sprintf(buf,"%1.0f",a);
lcd_puts(buf);
lcd_gotoxy(0,1);
b=a*5/255;
sprintf(buf2,"volt = %1.2f",b);
lcd_puts(buf2);
delay_ms(100);
}
}