狠狠撸

狠狠撸Share a Scribd company logo
Alexandre Zambotti Rodrigues
Gabriel Silva Marcatto
Rafael de Moura Moreira
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
while(a==a); //N?o é um loop infinito!
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
void main (void){
char *ptr;
//pointing to the port D
ptr = 0xF83;
//changing all outputs to high
*ptr = 0xFF;
}
19/11/2016
#define PORTD (*(volatile __near unsigned char*)0xF83)
#define TRISC (*(volatile __near unsigned char*)0xF94)
//this is not an infinite loop!
while( PORTD == PORTD);
19/11/2016
char mask;
mask = 1 << 2;
arg = arg | mask;
//one line
arg = arg | (1<<bit);
//using define
#define BitSet(arg,bit) ((arg) |= (1<<bit))
#define BitClr(arg,bit) ((arg) &= ~(1<<bit))
#define BitFlp(arg,bit) ((arg) ^= (1<<bit))
#define BitTst(arg,bit) ((arg) & (1<<bit))
19/11/2016
19/11/2016
19/11/2016
19/11/2016
19/11/2016
#define PORTD (*(volatile __near unsigned
char*)0xF83)
#define TRISD (*(volatile __near unsigned
char*)0xF95)
void main(void) {
TRISD = 0x00;
for(;;){
PORTD ^= 0xFF;
//delay();
}
}
19/11/2016
19/11/2016
19/11/2016
19/11/2016
#define TRISA (*(volatile __near unsigned char*)0xF92)
#define ADCON2 (*(volatile __near unsigned char*)0xFC0)
#define ADCON1 (*(volatile __near unsigned char*)0xFC1)
#define ADCON0 (*(volatile __near unsigned char*)0xFC2)
#define ADRESL (*(volatile __near unsigned char*)0xFC3)
#define ADRESH (*(volatile __near unsigned char*)0xFC4)
void adInit(void) {
BitSet(TRISA, 0); //pin setup
ADCON0 = 0b00000001; //channel select
ADCON1 = 0b00001110; //ref = source
ADCON2 = 0b10101010; //t_conv = 12 TAD
}
19/11/2016
unsigned int adRead(void){
unsigned int ADvalue;
BitSet(ADCON0,1); //start conversion
while(BitTst(ADCON0,1)); //wait
ADvalue = ADRESH; //read result
ADvalue <<= 8;
ADvalue += ADRESL;
return ADvalue;
}
19/11/2016
void main(void) {
unsigned int i;
unsigned int ad;
TRISD = 0x00;
adInit();
for (;;) {
ad = adRead();
PORTD = 0xff;
for (i = 0; i < ad;
i++);
PORTD = 0x00;
for (i = ad; i <
1024; i++);
}
}
19/11/2016
19/11/2016
19/11/2016
19/11/2016
#define RS 6
#define EN 7
void delayMicroseconds(int ms) {
int i;
for (; ms > 0; ms--) {
for (i = 0; i < 30; i++);
}
}
void pulseEnablePin() {
BitClr(PORTC, EN);
delayMicroseconds(1);
// send a pulse to enable
BitSet(PORTC, EN);
delayMicroseconds(1);
BitClr(PORTC, EN);
}
19/11/2016
void pushNibble(int value, int rs) {
PORTD = value;
if (rs) {
BitSet(PORTC, RS);
} else {
BitClr(PORTC, RS);
}
pulseEnablePin();
}
void pushByte(int value, int rs) {
int val_lower = value & 0x0F;
int val_upper = value >> 4;
pushNibble(val_upper, rs);
pushNibble(val_lower, rs);
}
19/11/2016
void lcdCommand(int value) {
pushByte(value, 0);
delayMicroseconds(40);
}
void lcdChar(int value) {
pushByte(value, 1);
delayMicroseconds(2);
}
19/11/2016
void lcdInit() {
BitClr(TRISC, EN);
BitClr(TRISC, RS);
TRISD = 0x0f;
delayMicroseconds(50);
commandWriteNibble(0x03);
delayMicroseconds(5);
commandWriteNibble(0x03);
delayMicroseconds(100);
commandWriteNibble(0x03);
delayMicroseconds(5);
commandWriteNibble(0x02);
delayMicroseconds(10);
//display config
lcdCommand(0x28); //4bits, 2 linhas, 5x8
lcdCommand(0x06); //incremental mode
lcdCommand(0x0c); //display on, cursor and blink
off
lcdCommand(0x03); //clean internal variables
lcdCommand(0x80); //initial position
lcdCommand(0x01); //clear display
delayMicroseconds(2);
}
19/11/2016
19/11/2016
19/11/2016
void lcdBsidesLogo(void) {
int i;
unsigned char bsides[] = {
0b00111, 0b00100, 0b00100, 0b00100, 0b00111,
0b00100, 0b00100, 0b00100, 0b10000, 0b01001,
0b01001, 0b01011, 0b10010, 0b01010, 0b01010,
0b11011, 0b01111, 0b11001, 0b00000, 0b00110,
0b00110, 0b00000, 0b00000, 0b00001, 0b00000,
0b11000, 0b01000, 0b01100, 0b00100, 0b00100,
0b00000, 0b11100, 0b00111, 0b00000, 0b00100,
0b00100, 0b00110, 0b00010, 0b00011, 0b00000,
0b10011, 0b00000, 0b00000, 0b01100, 0b01100,
0b00000, 0b10011, 0b11110, 0b10011, 0b10010,
0b11011, 0b01001, 0b11000, 0b10000, 0b10000,
0b00011, 0b00000, 0b00000, 0b00000, 0b11000,
0b01100, 0b00100, 0b01100, 0b11000, };
lcdCommand(0x40);
for (i = 0; i < 8 * 6; i++) {
lcdChar(~bsides[i]);
}
}
19/11/2016
19/11/2016

More Related Content

Desenvolvimento de Sistemas Embarcados - do hardware ao software