Thread: First post and doubts to make code work.

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    1

    First post and doubts to make code work.

    Hey:

    I a a new user to this forum (hi to all of you ) , so please forgive me if I am not posting this in the correct forum:

    I am new to programing and this semester at uni we have a course where we are tought C.

    My problem is the following: I have writen a function that is supposed to turn all the values in an array to 0 and then the microcontroller should print it on an LCD. I am using Atmel studio 7, the microcontroller is an Atmel328P and the setup is the following:

    Shared album - Alvaro Soler Verdu - Google Photos

    And this is my code. Thanks to everybody that reads or answeres!

    Code:
    #define F_CPU 16E6
    #include <avr/io.h>
    #include <stdio.h>
    #include <util/delay.h>
    #include "i2cmaster.h"
    #include "ds1621.h"
    #include "lcd.h"
    
    void printnumbers1(void);
    void reset_0(void);
    
        
    
    int array[8]={1,0,0,1,1,0,0,0};
    
        
    int main(void)
    {
        lcd_init(); 
        
        DDRD  = 0xFF; //I/O board:PD4...7 as outputs, for LEDs
        DDRC  = 0xF0; //I/O board PC0...3 as inputs, for buttons
        PORTC = 0x3F; // Enable internal pull at PC0..3 inputs
        PORTD = 0x00; // Set output LEDs to off
    
            
        while(1)
        {
                
    
    
            printnumbers1();        
                reset();        
        }
                    
    }        
    void printnumbers1(void)
    {
        int i=0;
            for (i=7; i>=0; i--)            //the function that prints array
            {
                lcd_gotoxy(1,i+1);            
                printf("%d", array[i]);            
            }
    }
    
    void reset_0(void)
    {    int u;
        if (PINC==0b00001110)
        {
        
            for (u=7;u>=0;u--)
            {
                array[u]=0;            
            }
            _delay_ms(300);
        }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Your display seems to show that printnumbers() works, is that correct?

    So the real issue is why reset() doesn't do what you want?

    Perhaps it's something to do with your function actually being called reset_0()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some doubts about not-working code
    By sleax in forum C Programming
    Replies: 7
    Last Post: 11-09-2015, 09:25 PM
  2. Replies: 8
    Last Post: 12-16-2012, 08:42 AM
  3. Replies: 10
    Last Post: 04-13-2010, 11:48 PM
  4. Just wanted to make a first post and say hello world.
    By FrogFace in forum General Discussions
    Replies: 17
    Last Post: 09-01-2009, 04:59 AM
  5. Replies: 21
    Last Post: 04-21-2009, 11:04 AM

Tags for this Thread