Feature #14290
Programmer le pic 18f sur Mplab pour le joystick
Status: | Closed | Start date: | 10/28/2022 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | - | Estimated time: | 8.00 hours | |
Target version: | Polytech Projets GE - Deuxième Itération 2022 | |||
Story points | - | Remaining (hours) | 8.00 hours | |
Velocity based estimate | - |
Subtasks
History
#1 Updated by Sokhna Mariama SECK 4 months ago
- Estimated time set to 8.00
Sur le projet Plamobo, en tant que développeur j'ai une carte avec un pic 16f sur laquelle je connecte un joystick afin de contrôler le robot.
J'ai besoin du code (en C) sur Mplab pour controler le robot.
Vous trouverez la datasheet du joystick en pièce jointe.
#2 Updated by Sokhna Mariama SECK 3 months ago
- Subject changed from Programmer le pic 16f sur Mplab pour le joystick to Programmer le pic 18f sur Mplab pour le joystick
#3 Updated by Louis FOUCHER 3 months ago
- Target version set to Polytech Projets GE - Première Itération 2022
#4 Updated by Louis FOUCHER 3 months ago
- Target version changed from Polytech Projets GE - Première Itération 2022 to Polytech Projets GE - Deuxième Itération 2022
#5 Updated by Louis FOUCHER 3 months ago
- Subject changed from Programmer le pic 18f sur Mplab pour le joystick to Programmer le pic 18f sur Mplab pour le joystick
- Status changed from New to In Progress
#6 Updated by Papa Abdoulaye NDIAYE 2 months ago
#if defined(_XC)
#include <xc.h> /* XC8 General Include File /
#elif defined(HI_TECH_C)
#include <htc.h> / HiTech General Include File /
#elif defined(_18CXX)
#include <p18cxxx.h> / C18 General Include File */
#endif
#if defined(__XC) || defined(HI_TECH_C)
#include <stdint.h> /* For uint8_t definition /
#include <stdbool.h> / For true/false definition */
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <pic18f45k50.h>
#endif
#include "system.h" /* System funct/params, like osc/peripheral config /
#include "user.h" / User funct/params, such as InitApp */
#define _XTAL_FREQ 4000000
#pragma config FOSC=INTOSCIO
#pragma config WDTEN=OFF
#pragma config MCLRE=OFF
#pragma config LVP=OFF
/**Je configure 1 sortie PWM sur les I/O C1**/
void PWM_init()
{
//PWM period = [(PR2) + 1] x 4 x Tosc x (TMR2 prescale value)
//PR2=(period/ToscxTMR2prescalex4)-1
short int period = 1/1000 ; // ms hz
PR2=(((period)*_XTAL_FREQ)/16)-1;
//PR2=100;//Period Register 2: defini la periode de l MLI
CCPR1L=12;
CCP1CON=0b00001100;//SET PWM Mode
CCPR2L=12;
CCP2CON=0b00001100;//SET PWM Mode
T2CONbits.TMR2ON=1;//Set timer 2
}
void PWM1
{
duty_cycle=(duty_cycle-511)/(1023-511);
CCPR1L=PR2*duty_cycle/100;
}
void PWM2
{
duty_cycle=(511- duty_cycle)/(511);
CCPR2L=PR2*duty_cycle/100;
}
void ADC_Init()
{
TRISA = 0xff; /*set as input port*/
ADCON1 = 0x0e; /*ref vtg is VDD and Configure pin as analog pin*/
ADCON2 = 0x92; /*Right Justified, 4Tad and Fosc/32. /
ADRESH = 0; /*Flush ADC output Register/
ADRESL = 0;
}
int ADC_Read(int channel)
{
int digital;
ADCON0 =(ADCON0 & 0b11000011)|((channel<<2) & 0b00111100); /*channel 0 is selected i.e (CHS3CHS2CHS1CHS0=0000)
and ADC is disabled i.e ADON=0*/
ADCON0 |= ((1<<ADON)|(1<<GO)); /*Enable ADC and start conversion*/
while(ADCON0bits.GO_nDONE==1); /*wait for End of conversion i.e. Go/done'=0 conversion completed*/
digital = (ADRESH*256) | (ADRESL); /*Combine 8-bit LSB and 2-bit MSB*/
return(digital);
}
void main(void)
{
/* Configure the oscillator for the device */
ConfigureOscillator();
/* Initialize I/O and Peripherals for application /
InitApp();
PWM_init();
ADC_Init();
/ TODO <INSERT USER APPLICATION CODE HERE> */
ANSELC=0;
TRISCbits.TRISC1=0;//PWM1
TRISCbits.TRISC2=0;//PWM2
int x,y;
while(1)
{
x=ADC_READ(0);
if(x>511)
{
PMW1(x);
}
else
{
PMW2(x);
}
}
}
#7 Updated by Sokhna Mariama SECK 2 months ago
- Status changed from In Progress to Closed
#8 Updated by Sokhna Mariama SECK 2 months ago
- File Joy1.X.zip added
#9 Updated by Sokhna Mariama SECK 2 months ago
- File Joy1.X - Copie.zip added