Sari la conținut
ELFORUM - Forumul electronistilor

Problema programare atmega 32


Postări Recomandate

Am vrut sa setez fusebitii pe 16mhz external cristal resonator si pe urma se pare ca nu mai programa cipul! am schimbat conzii de 22pf am schimbat cristalul, am alimentat extern cipul, dar nu a functionat nimik! trebuie sa mai incerc cu oscilator extern dar la magazin nu avea, am sa caut si-n alta parte. Intrebarea mea este ce sa putut intampla? Daca mai aveti alte idee ce sa mai incerc...le pun in aplicare! cristalul e montat corect, fusebitii i-am calculat corect, am verificat legaturile si tot degeaba! am verificat tot de 10 ori si cu datasheetul in fata si am facut aceeasi pasi cu un atmega8 sa fiu sigur ca eu am gresit dar cu atmega 8 totul mi-a mers bine si am schimabt fusebitii exat la fel cum i-am setat pe atmega32, si pe atmega8 il pot citi si scrie fara probleme. An AVRPROG MKII si pentru programat folosesc AVR Studio si AVR DUDE. Eu nu stiu ce sa-i mai fac, poate imi dati voi o idee!

Link spre comentariu
  • Răspunsuri 10
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

Salut,

Nu stiu daca este la fel si cu 32 (trebuie sa fie la fel), dar la atmega8 chiar zilele trecute am inscriptionat mai multe programe ce aveau nevoie de cristal de 16MHz. Dupa ce am fixat fusebitii la 16MHz, nu am mai putut utiliza MC-ul la frecventa mai mica sau sa-l rescriu. Eu am construit un fuse doctor de aici : http://mdiy.pl/atmega-fusebit-doctor-hvpp/ , care este "foarte util la casa omului" , atit pentru deblocare fusebiti cit si pentru astfel de situatii, aducind setarile MC-ului la cele de fabrica (la atmega8 la 1MHz).

Bafta.

Link spre comentariu

am incercat cu alte 2 quartzuri care le-am folosit in alte proiecte si eram sigur ca functioneaza (tot de 16 mhz) si cu CKOPT = 0 si =1 si tot degeaba. am sa fac fusebit doctor si am sa vad daca functioneaza asa. pe atmega 8 aceeasi config. aceleasi setari functioneaza in toate cazurile! probabil sa transmis vre-un bit eronat si mi-a blocat uC-ul ca am mai citit pe net ca sa mai intamplat in mai mult de 3-4 cazuri (persoane diferite) tot cu atmega 32, si o groaza care aveau atmega8(tot persoane diferite)

Link spre comentariu
  • 3 ani mai târziu...

buna seara, am programat un atmega 32 pentru afisarea pe un display lcd 2X16 DEM 16216, la montaj lcd-ul imi apar patrate linia 2 , ce se poate face in situatia asta ? sa fie gresit initiatilzarea lcd-ului? Multumesc

Codul este urmatorul :
 
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
 
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTC6
#define EN eS_PORTC7         // R/W connect to ground
 
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
 
#define RS_DDR DDRC
#define EN_DDR DDRC
#define RS_BIT PC6
#define EN_BIT PC7
 
#define DATA_DDR DDRD
#define D0_BIT PD0
#define D1_BIT PD1
#define D2_BIT PD2
#define D3_BIT PD3
#define D4_BIT PD4
#define D5_BIT PD5
#define D6_BIT PD6
#define D7_BIT PD7
 
#define MOTOR_DDR DDRA
#define MOTOR_PORT PORTA
#define MOTOR_PIN PINA
#define MOTOR_BIT PA0
 
#define SENSOR_DDR DDRA
#define SENSOR_PORT PORTA
#define SENSOR_PIN PINA
 
#define FULL_BIT PA1
#define QUAT_3_BIT PA2
#define HALF_BIT PA3
#define QAUT_BIT PA4
 
int quat, half, quat_3, full;
 
void Hardware_Init(){
// Display config OUTPUT pins
DATA_DDR |= _BV(D0_BIT);
DATA_DDR |= _BV(D1_BIT);
DATA_DDR |= _BV(D2_BIT);
DATA_DDR |= _BV(D3_BIT);
DATA_DDR |= _BV(D4_BIT);
DATA_DDR |= _BV(D5_BIT);
DATA_DDR |= _BV(D6_BIT);
DATA_DDR |= _BV(D7_BIT);
RS_DDR |= _BV(RS_BIT);
EN_DDR |= _BV(EN_BIT);
 
 
MOTOR_DDR |= _BV(MOTOR_BIT); // configure MOTOR pin as OUTPUT
MOTOR_PORT &= ~_BV(MOTOR_BIT); // set 0 logic to output motor bit
 
SENSOR_DDR &= ~_BV(FULL_BIT);
SENSOR_DDR &= ~_BV(QUAT_3_BIT);   // configure sensor pins as input
SENSOR_DDR &= ~_BV(HALF_BIT);
SENSOR_DDR &= ~_BV(QAUT_BIT);
 
}
 
int main(void){
 
Lcd8_Init();
 
while(1)
{
// read sensor pins
quat = SENSOR_PIN & _BV(QAUT_BIT);
half = SENSOR_PIN & _BV(HALF_BIT); 
quat_3 = SENSOR_PIN & _BV(QUAT_3_BIT); 
full = SENSOR_PIN & _BV(FULL_BIT); 
 
 
if(quat==0&&half==0&&quat_3==0&&full==0)   //when tank is empty
{
Lcd8_Cmd(0x80);   // to move the cursor to starting point of LCD
Lcd8_Write_String("EMPTY   ");      // dispalys empty on lcd 
MOTOR_PORT |= _BV(MOTOR_BIT); // start motor
}
else if(quat==1&&half==0&&quat_3==0&&full==0) // when tank is quater
{
Lcd8_Cmd(0x80); 
Lcd8_Write_String("QUATER   ");     // dispalys Quarter on lcd
}
else if(quat==1&&half==1&&quat_3==0&&full==0) // when tank is half
{
Lcd8_Cmd(0x80); 
Lcd8_Write_String("HALF    ");      // dispalys half on lcd
}
else if(quat==1&&half==1&&quat_3==1&&full==0) // when tank is three-fourth
{
Lcd8_Cmd(0x80); 
Lcd8_Write_String("3/4 FULL   ");     // dispalys 3/4 full on lcd
}
else if(quat==1&&half==1&&quat_3==1&&full==1) // when tank is full
{
Lcd8_Cmd(0x80); 
Lcd8_Write_String("FULL    ");    // dispalys full on lcd
MOTOR_PORT &= ~_BV(MOTOR_BIT);            // to stop the motor 
}
 
_delay_ms(100);
}
 
}
Link spre comentariu
aici este si codul pt lcd init :
//LCD Functions Developed by electroSome
#define eS_PORTA0 0
#define eS_PORTA1 1
#define eS_PORTA2 2
#define eS_PORTA3 3
#define eS_PORTA4 4
#define eS_PORTA5 5
#define eS_PORTA6 6
#define eS_PORTA7 7
#define eS_PORTB0 10
#define eS_PORTB1 11
#define eS_PORTB2 12
#define eS_PORTB3 13
#define eS_PORTB4 14
#define eS_PORTB5 15
#define eS_PORTB6 16
#define eS_PORTB7 17
#define eS_PORTC0 20
#define eS_PORTC1 21
#define eS_PORTC2 22
#define eS_PORTC3 23
#define eS_PORTC4 24
#define eS_PORTC5 25
#define eS_PORTC6 26
#define eS_PORTC7 27
#define eS_PORTD0 30
#define eS_PORTD1 31
#define eS_PORTD2 32
#define eS_PORTD3 33
#define eS_PORTD4 34
#define eS_PORTD5 35
#define eS_PORTD6 36
#define eS_PORTD7 37
 
#ifndef D0
#define D0 eS_PORTA0
#define D1 eS_PORTA1
#define D2 eS_PORTA2
#define D3 eS_PORTA3
#endif
 
#include<util/delay.h>
 
void pinChange(int a, int b)
{
if(b == 0)
{
if(a == eS_PORTA0)
 PORTA &= ~(1<<PA0);
else if(a == eS_PORTA1)
 PORTA &= ~(1<<PA1); 
else if(a == eS_PORTA2)
 PORTA &= ~(1<<PA2);
else if(a == eS_PORTA3)
 PORTA &= ~(1<<PA3); 
else if(a == eS_PORTA4)
 PORTA &= ~(1<<PA4); 
else if(a == eS_PORTA5)
 PORTA &= ~(1<<PA5); 
else if(a == eS_PORTA6)
 PORTA &= ~(1<<PA6);  
else if(a == eS_PORTA7)
 PORTA &= ~(1<<PA7);
else if(a == eS_PORTB0)
 PORTB &= ~(1<<PB0);  
else if(a == eS_PORTB1)
 PORTB &= ~(1<<PB1);
else if(a == eS_PORTB2)
 PORTB &= ~(1<<PB2);  
else if(a == eS_PORTB3)
 PORTB &= ~(1<<PB3);  
else if(a == eS_PORTB4)
 PORTB &= ~(1<<PB4);  
else if(a == eS_PORTB5)
 PORTB &= ~(1<<PB5);  
else if(a == eS_PORTB6)
 PORTB &= ~(1<<PB6);  
else if(a == eS_PORTB7)
 PORTB &= ~(1<<PB7);
else if(a == eS_PORTC0)
 PORTC &= ~(1<<PC0);
else if(a == eS_PORTC1)
 PORTC &= ~(1<<PC1); 
else if(a == eS_PORTC2)
 PORTC &= ~(1<<PC2);
else if(a == eS_PORTC3)
 PORTC &= ~(1<<PC3);
else if(a == eS_PORTC4)
 PORTC &= ~(1<<PC4);  
else if(a == eS_PORTC5)
 PORTC &= ~(1<<PC5);  
        else if(a == eS_PORTC6)
          PORTC &= ~(1<<PC6);
else if(a == eS_PORTC7)
 PORTC &= ~(1<<PC7);
else if(a == eS_PORTD0)
 PORTD &= ~(1<<PD0);
else if(a == eS_PORTD1)
 PORTD &= ~(1<<PD1);  
else if(a == eS_PORTD2)
 PORTD &= ~(1<<PD2);
else if(a == eS_PORTD3)
 PORTD &= ~(1<<PD3);
else if(a == eS_PORTD4)
 PORTD &= ~(1<<PD4);
else if(a == eS_PORTD5)
 PORTD &= ~(1<<PD5);
else if(a == eS_PORTD6)
 PORTD &= ~(1<<PD6);
else if(a == eS_PORTD7)
 PORTD &= ~(1<<PD7);        
}
else
{
if(a == eS_PORTA0)
 PORTA |= (1<<PA0);
else if(a == eS_PORTA1)
 PORTA |= (1<<PA1);
else if(a == eS_PORTA2)
 PORTA |= (1<<PA2);
else if(a == eS_PORTA3)
 PORTA |= (1<<PA3);
else if(a == eS_PORTA4)
 PORTA |= (1<<PA4);
else if(a == eS_PORTA5)
 PORTA |= (1<<PA5);
else if(a == eS_PORTA6)
 PORTA |= (1<<PA6);
else if(a == eS_PORTA7)
 PORTA |= (1<<PA7);
else if(a == eS_PORTB0)
   PORTB |= (1<<PB0);
else if(a == eS_PORTB1)
 PORTB |= (1<<PB1);
else if(a == eS_PORTB2)
 PORTB |= (1<<PB2);
else if(a == eS_PORTB3)
 PORTB |= (1<<PB3);
else if(a == eS_PORTB4)
 PORTB |= (1<<PB4);
else if(a == eS_PORTB5)
 PORTB |= (1<<PB5);
else if(a == eS_PORTB6)
 PORTB |= (1<<PB6);
else if(a == eS_PORTB7)
 PORTB |= (1<<PB7);
else if(a == eS_PORTC0)
 PORTC |= (1<<PC0);
else if(a == eS_PORTC1)
 PORTC |= (1<<PC1);
else if(a == eS_PORTC2)
   PORTC |= (1<<PC2);
else if(a == eS_PORTC3)
 PORTC |= (1<<PC3);
else if(a == eS_PORTC4)
 PORTC |= (1<<PC4);
else if(a == eS_PORTC5)
 PORTC |= (1<<PC5);
else if(a == eS_PORTC6)
 PORTC |= (1<<PC6);  
else if(a == eS_PORTC7)
 PORTC |= (1<<PC7);
else if(a == eS_PORTD0)
 PORTD |= (1<<PD0);
else if(a == eS_PORTD1)
 PORTD |= (1<<PD1);
else if(a == eS_PORTD2)
 PORTD |= (1<<PD2);
else if(a == eS_PORTD3)
 PORTD |= (1<<PD3);
else if(a == eS_PORTD4)
 PORTD |= (1<<PD4);
else if(a == eS_PORTD5)
 PORTD |= (1<<PD5);
else if(a == eS_PORTD6)
 PORTD |= (1<<PD6);
else if(a == eS_PORTD7)
 PORTD |= (1<<PD7);
}
}
 
 
 
//LCD 8 Bit Interfacing Functions
void Lcd8_Port(char a)
{
if(a & 1)
pinChange(D0,1);
else
pinChange(D0,0);
 
if(a & 2)
pinChange(D1,1);
else
pinChange(D1,0);
 
if(a & 4)
pinChange(D2,1);
else
pinChange(D2,0);
 
if(a & 8)
pinChange(D3,1);
else
pinChange(D3,0);
 
if(a & 16)
pinChange(D4,1);
else
pinChange(D4,0);
 
if(a & 32)
pinChange(D5,1);
else
pinChange(D5,0);
 
if(a & 64)
pinChange(D6,1);
else
pinChange(D6,0);
 
if(a & 128)
pinChange(D7,1);
else
pinChange(D7,0);
}
void Lcd8_Cmd(char a)
{
pinChange(RS,0);             // => RS = 0
Lcd8_Port(a);             //Data transfer
pinChange(EN,1);             // => E = 1
_delay_ms(1);
pinChange(EN,0);             // => E = 0
_delay_ms(1);
}
 
void Lcd8_Clear()
{
Lcd8_Cmd(1);
}
 
void Lcd8_Set_Cursor(char a, char b)
{
if(a == 1)
Lcd8_Cmd(0x80 + b);
else if(a == 2)
Lcd8_Cmd(0xC0 + b);
}
 
void Lcd8_Init()
{
pinChange(RS,0);
pinChange(EN,0);
_delay_ms(20);
///////////// Reset process from datasheet /////////
Lcd8_Cmd(0x30);
_delay_ms(5);
Lcd8_Cmd(0x30);
_delay_ms(1);
Lcd8_Cmd(0x30);
_delay_ms(10);
/////////////////////////////////////////////////////
Lcd8_Cmd(0x38);    //function set
Lcd8_Cmd(0x0C);    //display on,cursor off,blink off
Lcd8_Cmd(0x01);    //clear display
Lcd8_Cmd(0x06);    //entry mode, set increment
}
 
void Lcd8_Write_Char(char a)
{
pinChange(RS,1);             // => RS = 1
Lcd8_Port(a);             //Data transfer
pinChange(EN,1);             // => E = 1
_delay_ms(1);
pinChange(EN,0);             // => E = 04
_delay_ms(1);
}
 
void Lcd8_Write_String(char *a)
{
int i;
for(i=0;a!='0';i++)
Lcd8_Write_Char(a);
}
 
void Lcd8_Shift_Right()
{
Lcd8_Cmd(0x1C);
}
 
void Lcd8_Shift_Left()
{
Lcd8_Cmd(0x18);
}
//End LCD 8 Bit Interfacing Functions
 
//LCD 4 Bit Interfacing Functions
 
void Lcd4_Port(char a)
{
if(a & 1)
pinChange(D4,1);
else
pinChange(D4,0);
 
if(a & 2)
pinChange(D5,1);
else
pinChange(D5,0);
 
if(a & 4)
pinChange(D6,1);
else
pinChange(D6,0);
 
if(a & 8)
pinChange(D7,1);
else
pinChange(D7,0);
}
void Lcd4_Cmd(char a)
{
pinChange(RS,0);             // => RS = 0
Lcd4_Port(a);
pinChange(EN,1);            // => E = 1
_delay_ms(1);
pinChange(EN,0);             // => E = 0
_delay_ms(1);
}
 
void Lcd4_Clear()
{
Lcd4_Cmd(0);
Lcd4_Cmd(1);
}
 
void Lcd4_Set_Cursor(char a, char b)
{
char temp,z,y;
if(a == 1)
{
temp = 0x80 + b;
z = temp>>4;
y = (0x80+b) & 0x0F;
Lcd4_Cmd(z);
Lcd4_Cmd(y);
}
else if(a == 2)
{
temp = 0xC0 + b;
z = temp>>4;
y = (0xC0+b) & 0x0F;
Lcd4_Cmd(z);
Lcd4_Cmd(y);
}
}
 
void Lcd4_Init()
{
Lcd4_Port(0x00);
_delay_ms(20);
///////////// Reset process from datasheet /////////
Lcd4_Cmd(0x03);
_delay_ms(5);
Lcd4_Cmd(0x03);
_delay_ms(11);
Lcd4_Cmd(0x03);
/////////////////////////////////////////////////////
Lcd4_Cmd(0x02);
Lcd4_Cmd(0x02);
Lcd4_Cmd(0x08);
Lcd4_Cmd(0x00);
Lcd4_Cmd(0x0C);
Lcd4_Cmd(0x00);
Lcd4_Cmd(0x06);
}
 
void Lcd4_Write_Char(char a)
{
char temp,y;
temp = a&0x0F;
y = a&0xF0;
pinChange(RS,1);             // => RS = 1
Lcd4_Port(y>>4);             //Data transfer
pinChange(EN,1);
_delay_ms(1);
pinChange(EN,0);
_delay_ms(1);
Lcd4_Port(temp);
pinChange(EN,1);
_delay_ms(1);
pinChange(EN,0);
_delay_ms(1);
}
 
void Lcd4_Write_String(char *a)
{
int i;
for(i=0;a!='0';i++)
Lcd4_Write_Char(a);
}
 
void Lcd4_Shift_Right()
{
Lcd4_Cmd(0x01);
Lcd4_Cmd(0x0C);
}
 
void Lcd4_Shift_Left()
{
Lcd4_Cmd(0x01);
Lcd4_Cmd(0x08);
}
//End LCD 4 Bit Interfacing Functions
 
Editat de Mihai78
Link spre comentariu

Alătură-te conversației

Poți posta acum și să te înregistrezi mai târziu. Dacă ai un cont, autentifică-te acum pentru a posta cu contul tău.
Notă: Postarea ta va necesita aprobare moderator înainte de a fi vizibilă.

Vizitator
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Răspunde la acest subiect...

×   Alipit ca text avansat.   Restituie formatare

  Doar 75 emoji sunt permise.

×   Linkul tău a fost încorporat automat.   Afișează ca link în schimb

×   Conținutul tău precedent a fost resetat.   Curăță editor

×   Nu poți lipi imagini direct. Încarcă sau inserează imagini din URL.




×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări