caramoan tour package

caramoan tour package

Author Topic: 8051 Noob!!! heheh  (Read 4296 times)

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
8051 Noob!!! heheh
« on: September 18, 2009, 12:27:29 AM »
I start just tonight using protues. And just trying to be comfortable... yung ds89c4x0 talaga ang aaralin ko. but since may at89c2051 sa proteus, nagtry lang ako...

so here goes.

I use Keil 8.05 (may mga bago nang version, ewan ko kung bakit nagkakaroon ng problem sa licensing). here is my first code.

Code: [Select]
#include < AT892051.h >
 

void my_delay (void)
{
unsigned int i;
for (i=0;i<0xFFFF;i++);
}

void main( void )
{

P1_0 = 0; // initialize P1.0 = 0;

while(1)
{
P1_0 = 1;
my_delay();
P1_0 = 0;
my_delay();
}
}
 

so ok, nagwowork yan...

however, bakit di magwork kung gawing kong ganito?
Code: [Select]
while(1)
{
P1_0 ^= 1;
my_delay();
//P1_0 = 0;
//my_delay();
}


Saan nga ba nakakakuha nung MIDE for SDCC? I already got SDCC (v2.9.0). I must try this compiler kasi open source... legal kung baga.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

8051 Noob!!! heheh
« on: September 18, 2009, 12:27:29 AM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10767
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: 8051 Noob!!! heheh
« Reply #1 on: September 18, 2009, 12:39:58 AM »
http://www.opcube.com/home.html#MIDE51

MIDE-51 sis. ;)

ayaw mag-compile? try mo na lang sis na P1_0 = P1_0 ^ 1;
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Philippine Electronics Forum

Re: 8051 Noob!!! heheh
« Reply #1 on: September 18, 2009, 12:39:58 AM »

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #2 on: September 18, 2009, 12:51:32 AM »
^thanks... BTW, nagcocompile yun...

eto bago! natry ko na yung TIMER0 using 16-bit.

Code: [Select]
#include < AT892051.h > /* Include 89C2051 header file */
 
char const MAP[  ] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };

void timer0_init (void)
{
//T0_GATE_ = 0;
TMOD = TMOD & ~0x08;
//T0_CT_ = 0;
TMOD = TMOD & ~0x04;
//T0_M1_ = 0;
TMOD = TMOD & ~0x20;
//T0_M0 = 1; //16-bit
TMOD = TMOD | 0x10;
TR0 = 1;
}

void main( void )
{
unsigned int i;
timer0_init();

P1 = 0x00; // initialize P1.0 = 0;

while(1)
{
if(TF0)
{
TF0 = 0;
i++;
if (i>=8) i = 0;
P1 = MAP[i];
}
}
}
 

working, pero sobrang bilis. binibilang mo din ba ang several overflow? anong usually na ginagawa sa 8051 since walang prescaling?  <== using 12Mhz pala to.

reference: http://www.dnatechindia.com/index.php/Tutorials/8051-Tutorial/Timer.html
lagay ko lang para makatulong din sa iba...
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: 8051 Noob!!! heheh
« Reply #2 on: September 18, 2009, 12:51:32 AM »

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #3 on: September 18, 2009, 12:55:37 AM »

ayaw mag-compile? try mo na lang sis na P1_0 = P1_0 ^ 1;


di rin nagwork... parang wala lang... weird. wala namang mali di ba?
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: 8051 Noob!!! heheh
« Reply #3 on: September 18, 2009, 12:55:37 AM »

insomartin

  • Guest
Re: 8051 Noob!!! heheh
« Reply #4 on: September 18, 2009, 02:10:02 AM »
just checking around... !
procrastination mode. enabled
insomnia mode. enabled
coffee. hot

Philippine Electronics Forum

Re: 8051 Noob!!! heheh
« Reply #4 on: September 18, 2009, 02:10:02 AM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10767
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: 8051 Noob!!! heheh
« Reply #5 on: September 18, 2009, 02:13:17 AM »
di rin nagwork... parang wala lang... weird. wala namang mali di ba?

sa PIC umaandar ba 'yun sis? ang ginagawa ko kasi Px = !Px. ;D

ang ginagawa ko sa timer, multiple nga. kaya madalas mahaba 'yung timer interrupt ko. pero typical naka-set ako sa 1mS to 10mS interrupt.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline ATE

  • Size C Battery
  • *****
  • Posts: 225
  • Pogi/Ganda Points: 12
  • -.-
    • Volts and Bytes
Re: 8051 Noob!!! heheh
« Reply #6 on: September 18, 2009, 06:13:42 AM »
di rin nagwork... parang wala lang... weird. wala namang mali di ba?

sa MIDE P1_0 is ok to access Port 1 bit 0.

sa keil dapat ata P1^0 to access Port 1 bit 0;)

Quote
while(1)
   {
      P1^0 = 1;
   my_delay();
      P1^0 = 0;
      my_delay();
   }

Offline ATE

  • Size C Battery
  • *****
  • Posts: 225
  • Pogi/Ganda Points: 12
  • -.-
    • Volts and Bytes
Re: 8051 Noob!!! heheh
« Reply #7 on: September 18, 2009, 07:13:28 AM »
pwede din ata to

Quote
while(1)
{
P1^0 = ~P1^0;
my_delay();
}

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: 8051 Noob!!! heheh
« Reply #8 on: September 18, 2009, 07:22:40 AM »
BTW, SDCC is very good at compiling 8051 apps and is primarily made for it.
The Cebuano Geek

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #9 on: September 18, 2009, 10:11:12 AM »
sa PIC umaandar ba 'yun sis? ang ginagawa ko kasi Px = !Px. ;D

ang ginagawa ko sa timer, multiple nga. kaya madalas mahaba 'yung timer interrupt ko. pero typical naka-set ako sa 1mS to 10mS interrupt.

oo sis... umaandara yun. RB0 ^= 1;

timer naman... ewan ko lang kung sa proteus. pero eto yung calculation ko. sa 12Mhz, may 1us each increment. dun sa posted code code ko, 16-bits ang intented na timer. so 1us x 65536 = 65.536ms ang bawat overflow. therefore kailangan ko ng 15-16 overflows to make a 1 second... tama ba sis?

so ganito ang ginawa ko...
Code: [Select]
#define OVERFLOW_1S 15
while(1)
{
if(TF0)
{
TF0 = 0;
overflows++;
if (overflows >= OVERFLOW_1S)
{
overflows = 0;
i++;
if (i>=8) i = 0;
P1 = MAP[i];
}
}
}

pero yung outcome, mabilis pa din... weirdly(or talagang di pa ako sanay... hehehe) kung ilagay ko OVERFLOW_1S = 150, parang tamang tama yung bilis.


sa MIDE P1_0 is ok to access Port 1 bit 0.

sa keil dapat ata P1^0 to access Port 1 bit 0;)


kuya, di po tuloy na compile... i looked at the library files (headers files), P1_0 talga...

here, i'm posting the whole header file:
Code: [Select]
/*--------------------------------------------------------------------------
AT89x051.H

Header file for the Atmel 89C1051U, 89C2051, 89C4051.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __AT89x051_H__
#define __AT89x051_H__

/*------------------------------------------------
Byte Registers
------------------------------------------------*/
sfr SP      = 0x81;
sfr DPL     = 0x82;
sfr DPH     = 0x83;
sfr PCON    = 0x87;
sfr TCON    = 0x88;
sfr TMOD    = 0x89;
sfr TL0     = 0x8A;
sfr TL1     = 0x8B;
sfr TH0     = 0x8C;
sfr TH1     = 0x8D;
sfr P1      = 0x90;
sfr SCON    = 0x98;
sfr SBUF    = 0x99;
sfr IE      = 0xA8;
sfr P3      = 0xB0;
sfr IP      = 0xB8;
sfr PSW     = 0xD0;
sfr ACC     = 0xE0;
sfr B       = 0xF0;

/*------------------------------------------------
PCON Bit Values
------------------------------------------------*/
#define IDL_    0x01
#define STOP_   0x02
#define EWT_    0x04
#define EPFW_   0x08
#define WTR_    0x10
#define PFW_    0x20
#define POR_    0x40
#define SMOD_   0x80

/*------------------------------------------------
TCON Bit Registers
------------------------------------------------*/
sbit IT0  = 0x88;
sbit IE0  = 0x89;
sbit IT1  = 0x8A;
sbit IE1  = 0x8B;
sbit TR0  = 0x8C;
sbit TF0  = 0x8D;
sbit TR1  = 0x8E;
sbit TF1  = 0x8F;

/*------------------------------------------------
TMOD Bit Values
------------------------------------------------*/
#define T0_M0_   0x01
#define T0_M1_   0x02
#define T0_CT_   0x04
#define T0_GATE_ 0x08
#define T1_M0_   0x10
#define T1_M1_   0x20
#define T1_CT_   0x40
#define T1_GATE_ 0x80

#define T1_MASK_ 0xF0
#define T0_MASK_ 0x0F

/*------------------------------------------------
P1 Bit Registers
------------------------------------------------*/
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
sbit P1_3 = 0x93;
sbit P1_4 = 0x94;
sbit P1_5 = 0x95;
sbit P1_6 = 0x96;
sbit P1_7 = 0x97;

sbit AIN0 = 0x90;       /* + Analog comparator input */
sbit AIN1 = 0x91;       /* - Analog comparator input */

/*------------------------------------------------
SCON Bit Registers
------------------------------------------------*/
sbit RI   = 0x98;
sbit TI   = 0x99;
sbit RB8  = 0x9A;
sbit TB8  = 0x9B;
sbit REN  = 0x9C;
sbit SM2  = 0x9D;
sbit SM1  = 0x9E;
sbit SM0  = 0x9F;

/*------------------------------------------------
IE Bit Registers
------------------------------------------------*/
sbit EX0  = 0xA8;       /* 1=Enable External interrupt 0 */
sbit ET0  = 0xA9;       /* 1=Enable Timer 0 interrupt */
sbit EX1  = 0xAA;       /* 1=Enable External interrupt 1 */
sbit ET1  = 0xAB;       /* 1=Enable Timer 1 interrupt */
sbit ES   = 0xAC;       /* 1=Enable Serial port interrupt */
sbit ET2  = 0xAD;       /* 1=Enable Timer 2 interrupt */

sbit EA   = 0xAF;       /* 0=Disable all interrupts */

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
/* P3_6 Hardwired as AOUT */
sbit P3_7 = 0xB7;

sbit RXD  = 0xB0;       /* Serial data input */
sbit TXD  = 0xB1;       /* Serial data output */
sbit INT0 = 0xB2;       /* External interrupt 0 */
sbit INT1 = 0xB3;       /* External interrupt 1 */
sbit T0   = 0xB4;       /* Timer 0 external input */
sbit T1   = 0xB5;       /* Timer 1 external input */
sbit AOUT = 0xB6;       /* Analog comparator output */

/*------------------------------------------------
IP Bit Registers
------------------------------------------------*/
sbit PX0  = 0xB8;
sbit PT0  = 0xB9;
sbit PX1  = 0xBA;
sbit PT1  = 0xBB;
sbit PS   = 0xBC;

/*------------------------------------------------
PSW Bit Registers
------------------------------------------------*/
sbit P    = 0xD0;
sbit FL   = 0xD1;
sbit OV   = 0xD2;
sbit RS0  = 0xD3;
sbit RS1  = 0xD4;
sbit F0   = 0xD5;
sbit AC   = 0xD6;
sbit CY   = 0xD7;

/*------------------------------------------------
Interrupt Vectors:
Interrupt Address = (Number * 8) + 3
------------------------------------------------*/
#define IE0_VECTOR 0  /* 0x03 External interrupt 0 */
#define TF0_VECTOR 1  /* 0x0B Timer 0 */
#define IE1_VECTOR 2  /* 0x13 External interrupt 1 */
#define TF1_VECTOR 3  /* 0x1B Timer 1 */
#define SIO_VECTOR 4  /* 0x23 Serial port */

#endif



BTW, SDCC is very good at compiling 8051 apps and is primarily made for it.

noted sir... i am struggling last night to make my M-IDE work. it always give a "runtime error". ewan ko po ngayong nagrestart na ako... ;D
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline subzer0

  • Diesel Generator
  • *
  • Posts: 1222
  • Pogi/Ganda Points: 38
  • Garbage In Garbage Out.
Re: 8051 Noob!!! heheh
« Reply #10 on: September 18, 2009, 10:41:46 AM »
naku di ko pa pala nakokontak si wan,magpapaburn ako ng writer.hex,pasali po ako dito.
Signing Off...

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10767
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: 8051 Noob!!! heheh
« Reply #11 on: September 18, 2009, 10:47:10 AM »
^ parang na-encounter ko na 'yung runtime error dati. 'di ko maalala ano ang ginawa. baka si Wan na-encounter na rin. kung matiyaga ka sis pwede ring sa notepad tapos command line compilation. ;D ako dati sa DOS prompt EDIT tapos compile.

'di ako sigurado sis bakit ganun. try mo sa interrupt gawin. 'di ko pa nagamit 'yung timer ng 8051 sa non-interrupt. hehe.

‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: 8051 Noob!!! heheh
« Reply #12 on: September 18, 2009, 10:54:14 AM »
so ok, nagwowork yan...

however, bakit di magwork kung gawing kong ganito?
Code: [Select]
while(1)
{
P1_0 ^= 1;
my_delay();
//P1_0 = 0;
//my_delay();
}


Saan nga ba nakakakuha nung MIDE for SDCC? I already got SDCC (v2.9.0). I must try this compiler kasi open source... legal kung baga.

This error maybe caused by the fact that 8051 has bit-banded memory which maps individual bits on a byte in certain regions of RAM.  The compiler may generate differently codes for this location.
This could be verified by looking at the resulting assembly listing of this code snippet.
The Cebuano Geek

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #13 on: September 18, 2009, 10:57:09 AM »
sir this one worked...
Code: [Select]
P1_0 =  !P1_0;
my_delay();
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10767
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: 8051 Noob!!! heheh
« Reply #14 on: September 18, 2009, 01:17:16 PM »
^ tama si master zerowing. nawala sa isip ko, madalas 'di tama 'yung bitwise operations sa per port pin, pero ok sa port mismo, kaya complement ang ginagamit ko. isa sa features ng 8051 'yun (na sa Cortex-M3 ko na lang ulit nagamit), 'yung bit-banding. may ibang address 'yung per bit para isang instruction lang 'yung gamit, wala nang masking tulad sa ibang MCU. merong size 'yung bit-addressable (bit-banded) for general purpose din. pero 'di 'to automatic sa SDCC.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #15 on: September 18, 2009, 01:30:43 PM »
^ tama si master zerowing. nawala sa isip ko, madalas 'di tama 'yung bitwise operations sa per port pin, pero ok sa port mismo, kaya complement ang ginagamit ko. isa sa features ng 8051 'yun (na sa Cortex-M3 ko na lang ulit nagamit), 'yung bit-banding. may ibang address 'yung per bit para isang instruction lang 'yung gamit, wala nang masking tulad sa ibang MCU. merong size 'yung bit-addressable (bit-banded) for general purpose din. pero 'di 'to automatic sa SDCC.

ayun working nga sa per port...

Code: [Select]
P1 = 0x00; // initialize P1 = 0;

while(1)
{
P1 ^= 0xFF;
my_delay();
}

sis, panay ang error ng M-IDE ko... access violation daw. eto sampol:


may special setup ka pa bang ginagawa?

isa pa nga pala, yung header files di automatic yung paghanap ng IDE. instead ganito pa ang ginagawa ko:
#include "C:\MIDE\sdcc\include\mcs51\at89x051.h"
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10767
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: 8051 Noob!!! heheh
« Reply #16 on: September 18, 2009, 01:49:46 PM »
'di ko maalala sis kung paano naayos 'yan. sa office kasi nagkaganyan dati. hintayin natin si wan, alam ko na-encounter niya rin 'yan.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #17 on: September 18, 2009, 02:00:54 PM »
^tige...

maganda to para sa students kasi... libre!!! heheh ;D

gusto ko din yung simplicity nung IDE. walang maraming arte.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline SpongeBob

  • Lead Acid Battery
  • *******
  • Posts: 660
  • Pogi/Ganda Points: 33
Re: 8051 Noob!!! heheh
« Reply #18 on: September 18, 2009, 02:04:31 PM »
^bakit sa akin sir wala naman problema installation ng MIDE, di kaya sa OS? XP SP2 sa kin

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: 8051 Noob!!! heheh
« Reply #19 on: September 18, 2009, 02:15:40 PM »
^sis, ewan ko nga... mine is sp3. baka may issue pa sa procei... core2 quad ako (kaya naka sp3 ako)..

hays....
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: 8051 Noob!!! heheh
« Reply #19 on: September 18, 2009, 02:15:40 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com