201401012230


Микроконтроллеры PIC: MikroE C v 6.00 и MiSimDE v.2.1.0
-------------------------------------------------------

    Noh.. ja mis saab edasi?
    Ei midagi.. räägib ennast tühjaks ja kõik.
    
    С Новым Годом!

Reading:

  http://www.mikroe.com/products
       /view/285/book-pic-microcontrollers-programming-in-c/
       
Downloads:

  http://www.mikroe.com/mikroc/pic/
  http://www.feertech.com/misim/
  http://java.sun.com (tested with jre-7u45-windows-x64)


Project 0. 00<->FF
------------------

Project options:

  MCU and Oscillator: P16F877 / 8.000
  Release
  Config:$2007: 0x3B7B
    RC Oscillator
    WDT: Disabled
    PUT: Disabled
    FLASH PM Code Protection: Disabled
    Brown-out Reset: Enabled
    LVISP: Disabled
    Data EE memory code protection: Disabled
    Flash PM WE: Enabled
    In-Circuit Debugger Mode: Disabled


blink.c

  void main() {
    TRISB = 0;           // set direction to be output

    do {
      PORTB = 0x00;      // Turn OFF LEDs on PORTB
      Delay_ms(1000);    // 1 second delay
      PORTB = 0xFF;      // Turn ON LEDs on PORTB
      Delay_ms(1000);    // 1 second delay
    } while(1);          // Endless loop
  }


MiSimDE 2.1 Edit Preferences Clock 0.1 MHz

Build all, now run misimDE210: 
  
  File -> Load Binary: blink.hex
  Plugins: 7 segment LED Config b
  Edit -> Preferences -> Processor: 
    Processor: 16F877, 
    Simulate: Accurately
    Clock rate (MHz): 0.1
    [v] Handle Interrupts for Step and Over
    [v] Fast Loop Simulation
    

Project 1. Stepper
------------------

Project options:

  MCU and Oscillator: P16F877 / 8.000
  Release
  Config:$2007: 0x3B7B
    RC Oscillator
    WDT: Disabled
    PUT: Disabled
    FLASH PM Code Protection: Disabled
    Brown-out Reset: Enabled
    LVISP: Disabled
    Data EE memory code protection: Disabled
    Flash PM WE: Enabled
    In-Circuit Debugger Mode: Disabled


void main() {
  int      x = 0;
  char seq[] = { 1, 3, 2, 6, 4, 12, 8, 9 };
  TRISB      = 0;

  do {
    PORTB = seq[x++];
    x = (x > 7) ? 0 : x;
    Delay_ms(1000);
  } while(1);
}


Build all, now run misimDE210: 
  
  File -> Load Binary: stepper.hex
  Plugins: 7 segment LED Config: d2 (2 hex digits on PORTB)
           Stepper config: PORTB 0213
  Edit -> Preferences -> Processor: 
    Processor: 16F877, 
    Simulate: Accurately
    Clock rate (MHz): 0.1
    [v] Handle Interrupts for Step and Over
    [v] Fast Loop Simulation


Project 2. 7-Segment DISPLAY
---------------------------------

Project options:

  MCU and Oscillator: P16F877 / 8.000
  Release
  Config:$2007: 0x3B7B
    RC Oscillator
    WDT: Disabled
    PUT: Disabled
    FLASH PM Code Protection: Disabled
    Brown-out Reset: Enabled
    LVISP: Disabled
    Data EE memory code protection: Disabled
    Flash PM WE: Enabled
    In-Circuit Debugger Mode: Disabled


7seg.c

  void main() {
    TRISB = 0;

    do {
      PORTB = 0x00;  
      Delay_ms(1000);
      PORTB = 0x01;  
      Delay_ms(1000);
      PORTB = 0x02;  
      Delay_ms(1000);
      PORTB = 0x04;  
      Delay_ms(1000);
      PORTB = 0x08;  
      Delay_ms(1000);
      PORTB = 0x10;  
      Delay_ms(1000);
      PORTB = 0x20;  
      Delay_ms(1000);
      PORTB = 0x40;  
      Delay_ms(1000);
    } while(1);      
  }


MiSimDE 2.1 Edit Preferences Clock 0.1 MHz

Build all, now run misimDE210: 
  
  File -> Load Binary: 7seg.hex
  Plugins: 7 segment LED Config b
  Edit -> Preferences -> Processor: 
    Processor: 16F877, 
    Simulate: Accurately
    Clock rate (MHz): 0.1
    [v] Handle Interrupts for Step and Over
    [v] Fast Loop Simulation


Project 3. LCD 2x24 8bit DATA bus
---------------------------------

Project options:

  MCU and Oscillator: P16F877 / 8.000
  Release
  Config:$2007: 0x3B7A

Note: View -> Library Manager (hurry up), check LCD prior to compiling:


LCD.c

  // LCD module connections
  sbit LCD_EN at RC2_bit;
  sbit LCD_RW at RC1_bit;
  sbit LCD_RS at RC0_bit;

  sbit LCD_D0 at RB0_bit;
  sbit LCD_D1 at RB1_bit;
  sbit LCD_D2 at RB2_bit;
  sbit LCD_D3 at RB3_bit;
  sbit LCD_D4 at RB4_bit;
  sbit LCD_D5 at RB5_bit;
  sbit LCD_D6 at RB6_bit;
  sbit LCD_D7 at RB7_bit;

  sbit LCD_EN_Direction at TRISC2_bit;
  sbit LCD_RW_Direction at TRISC1_bit;
  sbit LCD_RS_Direction at TRISC0_bit;

  sbit LCD_D0_Direction at TRISB0_bit;
  sbit LCD_D1_Direction at TRISB1_bit;
  sbit LCD_D2_Direction at TRISB2_bit;
  sbit LCD_D3_Direction at TRISB3_bit;
  sbit LCD_D4_Direction at TRISB4_bit;
  sbit LCD_D5_Direction at TRISB5_bit;
  sbit LCD_D6_Direction at TRISB6_bit;
  sbit LCD_D7_Direction at TRISB7_bit;
  // End LCD module connections

  char *text;

  void main() {
      INTCON = 0;                 // All interrupts disabled
      TRISA = 0x04;

      Lcd_Init();                 // LCD display initialization
      Lcd_Cmd(_LCD_CURSOR_OFF);   // LCD command (cursor off)
      Lcd_Cmd(_LCD_CLEAR);        // LCD command (clear LCD)

      text = "mikroElektronika";  // Define the first message
      Lcd_Out(1,1,text);
      text = "LCD example";       // Define the second message
      Lcd_Out(2,1,text);

      while (1);
  }

Build all, now run misimDE210: 
  
  File -> Load Binary: LCD.hex
  Plugins -> LCD Display -> config: 2x24, Port C:ERS & Port B:76543210
  Edit -> Preferences -> Processor: 
    Processor: 16F877, 
    Simulate: Accurately
    Clock rate (MHz): 0.1
    [v] Handle Interrupts for Step and Over
    [v] Fast Loop Simulation
  

