-
Notifications
You must be signed in to change notification settings - Fork 2
/
MCAL_PIC18F_DIO.C
71 lines (68 loc) · 2.45 KB
/
MCAL_PIC18F_DIO.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stdtypes.h"
#include "MCAL_PIC18F.h"
#include <pic16/pic18f452.h>
#include <stdio.h>
volatile GPIOXX* MCAL_PIC_getgpio(u8_t PORTxx){
GPIOXX* GPIOx;
switch (PORTxx){
case PORTa :
GPIOx->PORTX=(volatile u8_t *)(0x0F80);
GPIOx->TRISX=(volatile u8_t *)(0x0F92);
GPIOx->LATX=(volatile u8_t *)(0x0F89);
return GPIOx;break;
case PORTb :
GPIOx->PORTX=(volatile u8_t *)(0x0F81);
GPIOx->TRISX=(volatile u8_t *)(0x0F93);
GPIOx->LATX=(volatile u8_t *)(0x0F8A);
return GPIOx;break;
case PORTc :
GPIOx->PORTX=(volatile u8_t *)(0x0F82);
GPIOx->TRISX=(volatile u8_t *)(0x0F94);
GPIOx->LATX=(volatile u8_t *)(0x0F8B);
return GPIOx;break;
case PORTd :
GPIOx->PORTX=(volatile u8_t *)(0x0F83);
GPIOx->TRISX=(volatile u8_t *)(0x0F95);
GPIOx->LATX=(volatile u8_t *)(0x0F8C);
return GPIOx;break;
case PORTe :
GPIOx->PORTX=(volatile u8_t *)(0x0F84);
GPIOx->TRISX=(volatile u8_t *)(0x0F96);
GPIOx->LATX=(volatile u8_t *)(0x0F8D);
return GPIOx;break;
default:
return NULL;}
return 0;}
void MCAL_PIC_Init_Port(u8_t PORTxx){
if ((PORTxx==PORTd) || (PORTxx==PORTe)) {ADCON1=0xff;}
return;}
void MCAL_PIC_SetBitDir( u8_t PORTxx , u8_t bitx , u8_t dir){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);
if (dir==INPUT){set_bit(*(gpio->TRISX),bitx);}
else {clr_bit(*(gpio->TRISX),bitx);}
return;}
void MCAL_PIC_SetBitsDir( u8_t PORTxx , u8_t bitx , u8_t bit_counuter , u8_t dir){
int i ; for (i=0 ; i<bit_counuter;i++){MCAL_PIC_SetBitDir(PORTxx,bitx,dir); bitx++;}return ;}
void MCAL_PIC_SetPORTDir(u8_t PORTxx ,u8_t dir){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);
if (dir==INPUT){*(gpio->TRISX)=PORT_IN;}
else {*(gpio->TRISX)=PORT_OUT;}
}
void MCAL_PIC_SetBitVal( u8_t PORTxx , u8_t bitx , u8_t val){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);
if (val==0){set_bit(*(gpio->LATX),bitx);}
else {clr_bit(*(gpio->LATX),bitx);}
return;}
void MCAL_PIC_SetBitSVal( u8_t PORTxx , u8_t bitx , u8_t val,u8_t bit_counuter){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);
if (val==0){set_bits(*(gpio->LATX),bitx,val);}
else if(val==1) {clr_bits(*(gpio->LATX),bitx,val);}
}
void MCAL_PIC_SetPORTVal( u8_t PORTxx , u8_t val ){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx); *(gpio->LATX)=val; return;}
u8_t MCAL_PIC_GetBitVal ( u8_t PORTxx , u8_t bitx){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);
return get_bit(*(gpio->PORTX),bitx);}
u8_t MCAL_PIC_GetPINVal( u8_t PORTxx ){
GPIOXX* gpio=MCAL_PIC_getgpio(PORTxx);return *(gpio->PORTX);
}