cyril13110 a écrit :...
ce que je ne sais pas cest comment preparer le programme.
est ce que la conf materiel je la fait a l'identique du bootloader? est ce que si je charge un code avec une conf différente je vait sauter le bootloader?
est ce qu'il y a des lignes de codes particulières a taper?
si le HID bootloader MikroE reconnais ton MCU ..ça sent bon
tu n'as pas à te preoccuper du bootloader dans ton application ...
par contre la config sera celle du bootloader , en particulier pour FOSC
probablement 48MHz pour satisfaire à la liaison USB..
Le HID bootloader Mikroe se charge à ce que ton application, lors du chargement du programme,
ne deborde pas et ecrabouille le bootloader ..
par contre tu peux l'ecrabouiller toi meme si tu ecris dedans , ou si un bug t'envoie là ou il faut pas !
ça m'est arrivé !
exmple de programme pour un clicker2 18F87J50 avec booloader USB
utilise UART1,ADC et en option HID Terminal ( enlever la poussiere, il date de 2017 !)
on voit qu'il n'y a
Rien de special concernant le bootloader !
meme pour les vecteurs d'interruptions ..c'est transparent.
mais vaut mieux commencer par faire clignoter une led ..par contre les statistiques données par mIkroC sur la taille occupée par le programme que tu installes,RAM & ROM
ne tient pas compte du bootloader
Code : Tout sélectionner
sbit LD1 at LATD4_bit;
sbit LD2 at LATE4_bit;
sbit LD1_Direction at TRISD4_bit;
sbit LD2_Direction at TRISE4_bit;
sbit BP1 at RD7_bit;
sbit BP2 at RH3_bit;
sbit BP1_Direction at TRISD7_bit;
sbit BP2_Direction at TRISH3_bit;
sbit Etat_Bat at RJ5_bit;
sbit Etat_Bat_Direction at TRISJ5_bit;
sbit CS_PIN at LATD3_bit ;
sbit CS_PIN_Direction at TRISD3_bit;
unsigned char readbuff[64] absolute 0x500;
unsigned char writebuff[64] absolute 0x540;
int Tension;
const char chaine0[]="Cliker2 18F87J50 : Test ADC sur clicker2 \r\n ";
const char chaine1[]="Directory" Directory"\r\n";
const char chaine2[]="Projet : "Project"\r\n";
const char chaine3[]="Source MikroC : "Source"_"Version"_.c\r\n";
const char chaine4[]="FOSC interne 8MHz , Alim 3,3V \r\n";
const char chaine4[]="Q=8MHZ x PLL => 48MHz Alim 3,3V \r\n";
const char chaine5[]="Utilise Timer0,Timer1,HID USB,UART1 19200 \r\n";
const char chaine6[]=" \r\n";
const char *RS_Str[]={chaine0,chaine1,chaine2,chaine3,chaine4,chaine5,chaine6};
Byte TEXTE[128];
Byte * txt;
Byte CRam1[80];
Byte *p;
unsigned int i,j,k,l,m;
unsigned long Freq;
float f1,f2;
unsigned char buffer1[MAXLEN1];
unsigned int Index1,i1;
unsigned int UART1_DataReady;
unsigned char c1;
volatile unsigned int Flag_Timer0;
volatile unsigned int Cpt0;
volatile unsigned int Cpt1,Max_Timer1;
volatile int Flag_Timer1;
unsigned char sec;
volatile struct chbits { unsigned FrameErr:1;
unsigned Over:1;
unsigned disponible:1;
unsigned Tracking:1;
unsigned Store:1;
unsigned Dialogue:1;
unsigned Visible:1;
unsigned One_Shoot:1;
unsigned MCP_OK:1;
unsigned Sommeil:1;
unsigned Rb0:1;
unsigned First_Run:1;
unsigned Buffer1_Full:1 ;
unsigned dummy :3 ;
}Drapeaux ;
void Hardware_Init(void);
void UART1_Write_CText(const char *txt1);
void CRLF1(void);
void strConstRamCpy(char *dest, const char *source);
void fltToa (double x, unsigned char *str,char precision);
void Init_Timer0(void);
void Interrupts() iv 0x0008 ics ICS_AUTO
{
if((RC1IF_bit==1) && (RC1IE_bit==1))
{
if(OERR1_bit)
{
CREN1_bit = 0;
CREN1_bit = 1;
OERR1_bit = 0;
}
if(FERR1_bit) c1 = RCREG1;
c1 = RCREG1;
if ((c1==CR)|| (i1>=MAXLEN1))
{
UART1_DataReady=1;
if (i1 >=MAXLEN1)
{
UART1_DataReady=2;
Drapeaux.Buffer1_Full=1;
}
PIE2.RC1IE=0 ; buffer1[i1]=0;
Index1=i1;
i1=0;
c1=0;
}
else
{
buffer1[i1]=c1;
Index1=i1;
i1++;
}
}
if((TMR0IE_bit) && (TMR0IF_bit))
{
Cpt0++;
if(Cpt0>9)
{
Flag_Timer0=1;
TMR0IE_bit=0;
Cpt0=0;
}
TMR0H = 0x3C;
TMR0L = 0xB0;
TMR0H= 0x6D; TMR0L =0x84 ; TMR0IF_bit=0; }
if ( (TMR1IE_bit==1) && ( TMR1IF_bit==1))
{ Cpt1++;
if (Cpt1>=Max_Timer1)
{
Cpt1=0;
Flag_Timer1=1;
TMR1IE_bit=0;
}
TMR1H= 0x0B; TMR1L= 0xDB; PIR1.TMR1IF=0;
}
USB_Interrupt_Proc();
}
void PrintHex( unsigned char x)
{
ByteToHex(x ,txt); k=strlen(txt);*(txt+k)=32; *(txt+k+1)=0;
strcpy( &writebuff,txt);
while(!HID_Write(&writebuff,64));
}
void CRLF_HID()
{
*(&writebuff)=13;
*(&writebuff+1)=10;
*(&writebuff+2)=0;
while(!HID_Write(&writebuff,64));
}
void Arme_Timer1()
{
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xDC;
Cpt1=0;
Flag_Timer1=0;
TMR1ON_bit=1; TMR1IE_bit = 1;
}
void Init_Timer1(void)
{
T1CON = 0x23;
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xDC;
TMR1IP_bit=0; TMR1IE_bit = 1;
INTCON = 0xC0;
Cpt1=0;
Flag_Timer1=0;
Max_Timer1=40;
}
void Init_Timer0()
{
T0CON = 0x81;
TMR0H = 0x3C;
TMR0L = 0xB0;
T0CON.PSA=0; T0CON.T0PS2=1; T0CON.T0PS1=0; T0CON.T0PS0=0; T0CON.T0CS=0; T0CON.T08BIT=0 ; TMR0H= 0x6D; TMR0L =0x84 ; INTCON.TMR0IF=0; Cpt0=0;
Flag_Timer0=0;
INTCON2.TMR0IP=1;
INTCON.TMR0IE=1;
T0CON.TMR0ON=1;
}
void strConstRamCpy(char *dest, const char *source)
{
while(*source) *dest++ = *source++ ;
*dest = 0 ; }
void CRLF1()
{
UART1_Write(CR);
UART1_Write(LF);
}
void UART1_Write_CText(const char *t)
{
while (*t)
UART1_Write(*t++);
}
void RAZ_UART1()
{
buffer1[i1]=0;
Index1=0;
i1=0;
Drapeaux.Buffer1_Full=0;
c1=RCREG1;
c1=0;
UART1_DataReady=0;
PIE2.RC1IE=1 ;
}
void Hardware_Init(void)
{
TRISG=0xFF;
TRISA=0b11101111; TRISC=0b10111111; ADSHR_bit=1; ANCON0=0b11111000; ANCON1=0xFF; ADSHR_bit=0; TRISB.B0=1;
TRISB.B2=1; RBPU_bit=0;
CS_PIN_Direction=0;
CS_PIN=0;
Etat_Bat_Direction=1; BP1_Direction = 1; BP2_Direction = 1; LD1_Direction = 0; LD2_Direction = 0;
LD1 = 0; LD2 = 0;
}
void Init_ADC()
{
ADCON0.VCFG1=0; ADCON0.VCFG0=0; ADCON0.CHS3=0; ADCON0.CHS2=0;
ADCON0.CHS1=0;
ADCON0.CHS0=1;
ADCON0.ADON=1; ADCON1.ADFM=1; ADCON1.ADCAL=0;
ADCON1.ACQT2=1;
ADCON1.ACQT1=1;
ADCON1.ACQT0=0; ADCON1.ADCS1=1;
ADCON1.ADCS2=1;
ADCON1.ADCS0=0; ADSHR_bit=1; ANCON0=0b11111101; ANCON1=0xFF; ADSHR_bit=0;
}
void main()
{
OSCTUNE=0 ; OSCCON.IRCF2=1; OSCCON.IRCF1=1; OSCCON.IRCF0=0;
OSCCON.SCS1=1; OSCCON.SCS0=1;
Hardware_Init();
LD2=1;
txt=&TEXTE[0];
TEXTE[0]=0;
CRam1[0]=0;
Drapeaux.First_Run=0;
Max_Timer1=40;
LD2=0;
LD1=1;
UART1_Init(19200); UART1_Write(CLS);
Delay_ms(500);
CRLF1();
LD1=0;
txt=&TEXTE[0];
for (i=0;i<5;i++)
{
UART1_Write_CText(RS_Str[i]);
Delay_ms(100);
}
LD1=0;LD2=0;
HID_Enable(&readbuff,&writebuff); Delay_ms(8000);
for (i=0;i<5;i++)
{
strConstRamCpy( &writebuff,RS_Str[i]);
while(!HID_Write(&writebuff,64)) ;
Delay_ms(100);
}
strConstRamCpy( &writebuff," Verif Fosc (Khz) = ");
while(!HID_Write(&writebuff,64)) ;
Freq=Get_Fosc_kHz() ;
LongWordToStr(Freq, CRam1);
strcpy( &writebuff,CRam1);
while(!HID_Write(&writebuff,64)) ;
CRLF_HID();
ADC_Init();
LD1=0;
LD2=1;
j=0;
while(1)
{
Tension=0; ADCON0.B1 = 1; while (ADCON0.B1); _asm {
MOVF ADRESL,W
MOVWF _Tension
MOVF ADRESH,W
MOVWF _Tension+1
}
WordToStr(Tension,CRam1);
UART1_Write_CText("Analog CH1= ");
UART1_Write_Text(CRam1);
UART1_Write(TAB);
if (Tension >= 1010){
UART1_Write_Text("Rouge");
}
else if (Tension >= 990){
UART1_Write_Text("Orange");
}
else if (Tension >= 970){
UART1_Write_Text("Jaune");
}
else if (Tension < 970){
UART1_Write_Text("Vert");
}
else
UART1_Write_Text("....");
Delay_ms(1000);
CRLF1();
Delay_ms(100);
}
}