hardware:
-Motor DC
-Bridge H
-LM35 Temperature Sensor
-Potenciometro 50k Ohms
-LCD
-LEDs
Software:
-The LCD should start showing the student's name on the first line and the course name in the second line.
-If The push button key (CH1) connected to the INT0 interrupt pin is activated, it will allow the A / D conversion perform the pot,
and this converted value, to the motor PWM cycle;
-The Key CH2 and CH3 select the motor direction;
-For Both cases, the LCD shows:
"Motor powered" - First line of the display if the CH1 is triggered
"Duty PWM = xxx%" - Second line of the display if the CH2 switch is activated;
- "Temperature Sensor" - first line of the LCD, if CH1 is not pressed;
- "Temperature = XXºC" -Second line, CH1 is not pressed through the LED1 indicates the motor direction of rotation;
So, i'm coding my Pic 18F4550 in MPLAB, and i'm stuck, really, This is my code:
PLZ, can someone JUST HELP ME, PLZ, It's a hurry, I do really need to do this, if someone send me the complete code, do it your way or send me an example so I can understand better and FINISH IT!!
THX !!!
and sorry my bad english. ;P
Mod EDIT: Use code tags to make your code easier to read. Moved this thread to Homework Help.
-Motor DC
-Bridge H
-LM35 Temperature Sensor
-Potenciometro 50k Ohms
-LCD
-LEDs
Software:
-The LCD should start showing the student's name on the first line and the course name in the second line.
-If The push button key (CH1) connected to the INT0 interrupt pin is activated, it will allow the A / D conversion perform the pot,
and this converted value, to the motor PWM cycle;
-The Key CH2 and CH3 select the motor direction;
-For Both cases, the LCD shows:
"Motor powered" - First line of the display if the CH1 is triggered
"Duty PWM = xxx%" - Second line of the display if the CH2 switch is activated;
- "Temperature Sensor" - first line of the LCD, if CH1 is not pressed;
- "Temperature = XXºC" -Second line, CH1 is not pressed through the LED1 indicates the motor direction of rotation;
So, i'm coding my Pic 18F4550 in MPLAB, and i'm stuck, really, This is my code:
C:
#include<p18f4550.h>
#include<delays.h>
#include<pwm.h>
#pragma config CCP2MX=ON //PINO RC1 - ON
void TOPO (void);
void BOTO (void);
void nome(void);
void configuralcd(void);
void temperatura (void);
void atraso (unsigned char tempo);
void escreve_LETRA(unsigned char letra);
void escreve_CMD(unsigned char caracter);
void string (const rom char *i);
#define MAX 40
#define MAX1 500
#pragma code ALTA = 0x08 //Interrupção de ALTA prioridade
void ALTA (void)
{
TOPO();
}
#pragma code
#pragma code BAIXA = 0x18 //Interrupção de BAIXA prioridade
void BAIXA (void)
{
BOTO();
}
#pragma code
int duty_pwm=0;
int a=0;
char graus;
float X;
void main()
{
char dezena,unidade;
ADCON0bits.ADON=0; //Desliga o Conversor A/D
ADCON1= 0b00001111; //Todos os canais com Entrada Digital
RCONbits.IPEN=0; //Prioridade de Interrupção Desligada
INTCONbits.GIE=1; //Interrupções Globais Habilitadas
INTCONbits.PEIE=1; //Interrupções de Periféricos Habilitadas
INTCONbits.INT0IE=1; //Interrupção INT0 Habilitada
INTCONbits.INT0IF=0; //Flag de Interrupção ?Limpo?
INTCON2bits.INTEDG0=1; //Interrupção Sensível a Borda de Subida
DDRDbits.RD0=0; //RD0 Saida
DDRCbits.RC1=0; //RC1 Saida
//configuração da interrupção
ADCON1=0x0F; //Canais analógicos desligados
RCONbits.IPEN=1; //INT com prioridade = 1
INTCONbits.GIE=1; //INT Globlal = 1
INTCONbits.PEIE=1; //INT periferica = 1
INTCON2bits.INTEDG1=0;//INT 1 em Borda de DESCIDA
INTCON2bits.INTEDG2=1;//INT 2 em Borda de SUBIDA
INTCON3=0b01011000;
//configuração do timer
T2CONbits.T2CKPS0=0; // Pre-escala (PS)
T2CONbits.T2CKPS1=1; //vvvvvvvvv1:16vvvvvvvvv
T2CONbits.TMR2ON=1; //timer 2 = ON
T2CONbits.T2OUTPS0=0; //------------------------
T2CONbits.T2OUTPS1=0; // seleciona pós escala
T2CONbits.T2OUTPS2=1; // 1:16
T2CONbits.T2OUTPS3=1; //------------------------
TMR2=0x00; //Timer inicia em 0
PR2=38; //conta ate 38 e compara com o TRM2, pra gerar um
//pulso para a postcale
//configura o PWM
CCP2CONbits.CCP2M0=0; //-----------------
CCP2CONbits.CCP2M1=0; // Habilita o
CCP2CONbits.CCP2M2=1; // PWM2
CCP2CONbits.CCP2M3=1; //-----------------
configuralcd();
atraso(MAX);
nome();
while(1)
{
if(a==1)
{
ADCON0bits.GO=1;
while (ADCON0bits.GO==1);
escreve_CMD(0X01);
dezena=(graus/10)+48;
PORTEbits.RE0=1; //dezena
PORTEbits.RE1=1;
PORTD=dezena;
atraso(MAX);
PORTEbits.RE1=0;
atraso(MAX);
unidade=(graus%10)+48;
PORTEbits.RE0=1; //unidade
PORTEbits.RE1=1;
PORTD=unidade;
atraso(MAX);
PORTEbits.RE1=0;
atraso(MAX);
a=2;
}
if(a==2)
{
atraso(MAX1);
atraso(MAX1);
atraso(MAX1);
atraso(MAX1);
nome();
a=0;
}
}
}
#pragma interrupt TOP
void TOPO (void)
{
duty_pwm+=50; //incrementa 50
if (duty_pwm>156)
{
duty_pwm=156;
}
else
{
SetDCPWM2(duty_pwm);
}
INTCON3bits.INT1IF=0; //Int Flag vai pra 0
}
#pragma interrupt BOT
void BOTO (void)
{
duty_pwm-=50; //decrementa 50
if (duty_pwm<0)
{
duty_pwm=0;
}
else
{
SetDCPWM2(duty_pwm);
}
INTCON3bits.INT2IF=0; //Int Flag vai pra 0
}
void atraso (unsigned char tempo)
{
int i;
for(i=0;i<tempo;i++)
{
Delay1KTCYx(1);
Delay1KTCYx(1);
Delay1KTCYx(1);
Delay1KTCYx(1);
Delay1KTCYx(1);
}
}
void nome(void)
{
escreve_CMD(0X01);
string("STUDENT"); //Escreve a primeira linha do DISPLAY
escreve_CMD(0X00);
escreve_CMD(0XC0);
string("COURSE"); //Escreve a segunda linda do DISPLAY
}
void configuralcd(void)
{
escreve_CMD(0x30);//escolha de bits
escreve_CMD(0x38);//matriz
escreve_CMD(0x0F);//Cursor Piscante
escreve_CMD(0x06);//DESLOCAMENTO DO CURSOR
}
void escreve_CMD(unsigned char caracter)
{
PORTEbits.RE0=0; //COMANDOS
PORTEbits.RE1=1;
PORTD=caracter;
atraso(MAX);
PORTEbits.RE1=0;
atraso(MAX);
}
void escreve_LETRA(unsigned char letra)
{
PORTEbits.RE0=1; //DADOS
PORTEbits.RE1=1;
PORTD=letra;
atraso(MAX);
PORTEbits.RE1=0;
atraso(MAX);
}
void string (const rom char *i)
{
while(*i>0)
{
escreve_LETRA(*i++);
}
}
#pragma interrupt temperatura
void temperatura (void)
{
int result; //Variável de 16 bits
DDRAbits.RA0 = 1; //Pino A0 como entrada
ADCON0bits.ADON = 1; //Habilita o conversor A/D
PIE1bits.ADIE = 0; //Desliga a Interrupção por conversão A/D
ADCON0bits.CHS0 = 0; //------------------------
ADCON0bits.CHS1 = 0; // SELECIONA O CANAL
ADCON0bits.CHS2 = 0; // AN0
ADCON0bits.CHS3 = 0; //------------------------
ADCON1 = 0b00001110; //REFERENCIA DE Vss e VDD e o CANAL AN0 como analógico
ADCON2 = 0b10111101; //FOSC / 16
//TAD = 20x
//ADFM = Resultado Justificado á Direita
ADCON0bits.GO = 1; //Inicializa a Conversão (16 us de aquisição)
while (ADCON0bits.GO == 1); //Programa Fica parado no WHLE até que o bit GO vá para 0
result=((unsigned int)ADRESH<<8)|(ADRESL); //RESULTADO EM BINÁRIO
X=((float)result*5)/1023;
graus=(X*1)/0.01;
a=1;
INTCONbits.INT0IF=0; // limpa flag
}
THX !!!
and sorry my bad english. ;P
Mod EDIT: Use code tags to make your code easier to read. Moved this thread to Homework Help.
Last edited by a moderator: